Created
July 14, 2015 08:02
-
-
Save maciejlach/c8d5c9199caa8e768b04 to your computer and use it in GitHub Desktop.
ProxiedQConnection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import com.exxeleron.qjava.QConnection; | |
import com.exxeleron.qjava.QException; | |
public class ProxiedQConnection implements QConnection { | |
private final static Logger logger = LoggerFactory.getLogger(ProxiedQConnection.class); | |
private final com.exxeleron.qjava.QConnection proxied; | |
public ProxiedQConnection(final com.exxeleron.qjava.QConnection connection) { | |
proxied = connection; | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public synchronized void open() throws IOException, QException { | |
logger.info("Opening connection to: " + proxied); | |
proxied.open(); | |
logger.info("Connected to: " + proxied); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public synchronized void close() throws IOException { | |
logger.info("Closing connection to: " + proxied); | |
proxied.close(); | |
logger.info("Disconnected from: " + proxied); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public synchronized void reset() throws IOException, QException { | |
logger.debug("Reseting connection: " + proxied); | |
proxied.reset(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public synchronized boolean isConnected() { | |
return proxied.isConnected(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public synchronized Object sync( final String query, final Object... parameters ) throws QException, IOException { | |
try { | |
return proxied.sync(query, parameters); | |
} catch ( final IOException e ) { | |
logger.debug("Error while executing: " + query, e); | |
reset(); | |
return proxied.sync(query, parameters); | |
} | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public synchronized void async( final String query, final Object... parameters ) throws QException, IOException { | |
try { | |
proxied.async(query, parameters); | |
} catch ( final IOException e ) { | |
logger.debug("Error while executing: " + query, e); | |
reset(); | |
proxied.async(query, parameters); | |
} | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public synchronized Object receive( final boolean dataOnly, final boolean raw ) throws IOException, QException { | |
return proxied.receive(dataOnly, raw); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public synchronized int query( final MessageType msgType, final String query, final Object... parameters ) throws QException, IOException { | |
throw new UnsupportedOperationException(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public synchronized Object receive() throws IOException, QException { | |
return proxied.receive(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public String getHost() { | |
return proxied.getHost(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public int getPort() { | |
return proxied.getPort(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public String getUsername() { | |
return proxied.getUsername(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public String getPassword() { | |
return proxied.getPassword(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public String getEncoding() { | |
return proxied.getEncoding(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public int getProtocolVersion() { | |
return proxied.getProtocolVersion(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment