public abstract class AbstractProxyConnection extends Object implements Connection
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractProxyConnection.ProxiedChangeListener
ProxiedChangeListener provides a change listener to modify the source of
the event to the outer connection from the (inner) proxied connection.
|
Modifier and Type | Field and Description |
---|---|
protected MongoClientConfiguration |
myConfig
The MongoDB client configuration.
|
COMMAND_COLLECTION, OPEN_PROP_NAME
Constructor and Description |
---|
AbstractProxyConnection(Connection proxiedConnection,
MongoClientConfiguration config)
Creates a AbstractProxyConnection.
|
Modifier and Type | Method and Description |
---|---|
void |
addPending(List<PendingMessage> pending)
Adds the pending messages from the specified list.
|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a
PropertyChangeListener to this connection. |
void |
close()
Closes the underlying connection.
|
void |
drainPending(List<PendingMessage> pending)
Removes any to be sent pending messages into the specified list.
|
void |
flush() |
int |
getPendingCount()
Returns the number of messages that are pending responses from the
server.
|
protected Connection |
getProxiedConnection()
Returns the proxiedConnection value.
|
String |
getServerName()
Returns the name of a server the connection is currently connected to.
|
boolean |
isIdle()
Determines if the connection is idle.
|
boolean |
isOpen()
Determines if the connection is open.
|
protected void |
onExceptin(MongoDbException exception)
Provides the ability for derived classes to intercept any exceptions from
the underlying proxied connection.
|
void |
raiseErrors(MongoDbException exception,
boolean notifyToBeSent)
Notifies the call backs for the pending and optionally the to be sent
messages that there has been an external, unrecoverable error.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a
PropertyChangeListener from this connection. |
String |
send(Message message,
Callback<Reply> replyCallback)
Sends a message on the connection.
|
String |
send(Message message1,
Message message2,
Callback<Reply> replyCallback)
Sends a message on the connection.
|
void |
shutdown()
Notifies the connection that once all outstanding requests have been sent
and all replies received the Connection should be closed.
|
void |
waitForClosed(int timeout,
TimeUnit timeoutUnits)
Waits for the connection to become idle.
|
protected final MongoClientConfiguration myConfig
public AbstractProxyConnection(Connection proxiedConnection, MongoClientConfiguration config)
proxiedConnection
- The connection to forward to.config
- The MongoDB client configuration.public void addPending(List<PendingMessage> pending) throws InterruptedException
Overridden to forward to the wrapped connection.
addPending
in interface Connection
pending
- The list to populate the pending list with.InterruptedException
- On the thread being interrupted while copying the messages.public void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
to this connection. Events are
fired as the state of the connection changes.
Overridden to create a proxy connection if not already created and add the listener to that connection.
addPropertyChangeListener
in interface Connection
listener
- The listener for the change events.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Closeable.close()
public void drainPending(List<PendingMessage> pending)
Overridden to forward to the wrapped connection.
drainPending
in interface Connection
pending
- The list to populate with the pending messages.public void flush() throws IOException
Forwards the call to the proxied Connection
.
flush
in interface Flushable
IOException
Flushable.flush()
public int getPendingCount()
Forwards the call to the proxied Connection
.
getPendingCount
in interface Connection
public String getServerName()
Overridden to forward the call to the proxied connection.
getServerName
in interface Connection
public boolean isIdle()
Forwards the call to the proxied Connection
.
isIdle
in interface Connection
public boolean isOpen()
Forwards the call to the proxied Connection
.
isOpen
in interface Connection
public void raiseErrors(MongoDbException exception, boolean notifyToBeSent)
Forwards the call to the proxied Connection
.
raiseErrors
in interface Connection
exception
- The error condition.notifyToBeSent
- If true then the to be sent message's callback are also
notified, otherwise just the pending messages are notified.public void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
from this connection.
Overridden to create a proxy connection if not already created and add the listener to that connection.
removePropertyChangeListener
in interface Connection
listener
- The listener for the change events.public String send(Message message, Callback<Reply> replyCallback) throws MongoDbException
Forwards the call to the proxied Connection
.
send
in interface Connection
message
- The message to send on the connection.replyCallback
- The callback to notify of responses to the messages. May be
null
.MongoDbException
- On an error sending the message.public String send(Message message1, Message message2, Callback<Reply> replyCallback) throws MongoDbException
Forwards the call to the proxied Connection
.
send
in interface Connection
message1
- The first message to send on the connection.message2
- The second message to send on the connection.replyCallback
- The callback to notify of responses to the message2
.
May be null
.MongoDbException
- On an error sending the message.public void shutdown()
Forwards the call to the proxied Connection
.
shutdown
in interface Connection
public void waitForClosed(int timeout, TimeUnit timeoutUnits)
Forwards the call to the proxied Connection
.
waitForClosed
in interface Connection
timeout
- The amount of time to wait for the connection to become idle.timeoutUnits
- The units for the amount of time to wait for the connection to
become idle.protected Connection getProxiedConnection()
protected void onExceptin(MongoDbException exception)
Closes the underlying connection.
exception
- The thrown exception.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.