added connection listener

This commit is contained in:
leventov
2015-10-02 02:43:44 +03:00
parent 103a893a25
commit dad9de7ca2
2 changed files with 13 additions and 12 deletions
@@ -16,7 +16,7 @@
package net.openhft.chronicle.hash.replication;
import java.net.SocketAddress;
import java.net.InetAddress;
public interface ConnectionListener {
@@ -27,15 +27,14 @@ public interface ConnectionListener {
* we made the connection to a remote host then {@code isServer} is {@code
* false}
*/
void onConnect(SocketAddress address, byte identifier, boolean isServer);
void onConnect(InetAddress address, byte identifier, boolean isServer);
/**
* @param address the address that we have been disconnected from
* @param identifier the identifer the address that we have been disconnected from or Byte
* .MIN_VALUE if not known
*/
void onDisconnect(SocketAddress address, byte identifier);
void onDisconnect(InetAddress address, byte identifier);
}
@@ -394,9 +394,10 @@ public final class TcpReplicator<K, V> extends AbstractChannelReplicator impleme
if (LOG.isDebugEnabled())
LOG.debug("", e);
// todo OZAN :
// null check (Attached)key.attachment();
// connectionListener.onDiconnect( ((SocketChannel)key.channel()).socket().getInetAddress(), ((Attached)key.attachment()).remoteIdentifier);
if (key.channel() != null && key.attachment() != null)
connectionListener.onDisconnect(((SocketChannel) key.channel()).socket().getInetAddress(),
((Attached) key.attachment()).remoteIdentifier);
closeEarlyAndQuietly(key.channel());
@@ -509,7 +510,7 @@ public final class TcpReplicator<K, V> extends AbstractChannelReplicator impleme
*/
boolean isValidVersionNumber(String versionNumber) {
if (versionNumber.length()<=2)
if (versionNumber.length() <= 2)
return false;
for (char c : versionNumber.toCharArray()) {
@@ -587,10 +588,11 @@ public final class TcpReplicator<K, V> extends AbstractChannelReplicator impleme
attached.remoteIdentifier = remoteIdentifier;
// todo OZAN : add call to onConnectedListener.
//connectionListener. onConnected(channel.socket().getInetAddress() , attached
// .remoteIdentifier, attached.isServer );
final SocketChannel channel = (SocketChannel) key.channel();
if (channel != null && channel.socket() != null) {
connectionListener.onConnect(channel.socket().getInetAddress(),
attached.remoteIdentifier, attached.isServer);
}
// we use the as iterating the activeKeys via the bitset wont create and Objects
// but if we use the selector.keys() this will.
@@ -1130,8 +1132,8 @@ public final class TcpReplicator<K, V> extends AbstractChannelReplicator impleme
/**
* writes all the entries that have changed, to the buffer which will later be written to
* TCP/IP
* @param modificationIterator a record of which entries have modification
*
* @param modificationIterator a record of which entries have modification
*/
void entriesToBuffer(@NotNull final Replica.ModificationIterator modificationIterator) {