Added ability to add/remove custom connections to the server backed,
to allow for custom connection types (such as web-based) that we want our server to be able to manage + dispatch listeners
This commit is contained in:
parent
fa07a1b56a
commit
ad34679e71
@ -476,23 +476,7 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
|
|||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void connectionConnected(final C connection) {
|
void connectionConnected(final C connection) {
|
||||||
// synchronized is used here to ensure the "single writer principle", and make sure that ONLY one thread at a time can enter this
|
addConnection(connection);
|
||||||
// section. Because of this, we can have unlimited reader threads all going at the same time, without contention (which is our
|
|
||||||
// use-case 99% of the time)
|
|
||||||
synchronized (singleWriterLock2) {
|
|
||||||
// access a snapshot of the subscriptions (single-writer-principle)
|
|
||||||
ConcurrentEntry head = connectionsREF.get(this);
|
|
||||||
|
|
||||||
if (!connectionEntries.containsKey(connection)) {
|
|
||||||
head = new ConcurrentEntry<Object>(connection, head);
|
|
||||||
|
|
||||||
connectionEntries.put(connection, head);
|
|
||||||
|
|
||||||
// save this snapshot back to the original (single writer principle)
|
|
||||||
connectionsREF.lazySet(this, head);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
final IdentityMap<Type, ConcurrentIterator> listeners = listenersREF.get(this);
|
final IdentityMap<Type, ConcurrentIterator> listeners = listenersREF.get(this);
|
||||||
|
|
||||||
@ -593,6 +577,45 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
|
|||||||
removeListenerManager(connection);
|
removeListenerManager(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeConnection(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a custom connection to the server.
|
||||||
|
* <p>
|
||||||
|
* This should only be used in situations where there can be DIFFERENT types of connections (such as a 'web-based' connection) and
|
||||||
|
* you want *this* server instance to manage listeners + message dispatch
|
||||||
|
*
|
||||||
|
* @param connection the connection to add
|
||||||
|
*/
|
||||||
|
void addConnection(final C connection) {
|
||||||
|
// synchronized is used here to ensure the "single writer principle", and make sure that ONLY one thread at a time can enter this
|
||||||
|
// section. Because of this, we can have unlimited reader threads all going at the same time, without contention (which is our
|
||||||
|
// use-case 99% of the time)
|
||||||
|
synchronized (singleWriterLock2) {
|
||||||
|
// access a snapshot of the subscriptions (single-writer-principle)
|
||||||
|
ConcurrentEntry head = connectionsREF.get(this);
|
||||||
|
|
||||||
|
if (!connectionEntries.containsKey(connection)) {
|
||||||
|
head = new ConcurrentEntry<Object>(connection, head);
|
||||||
|
|
||||||
|
connectionEntries.put(connection, head);
|
||||||
|
|
||||||
|
// save this snapshot back to the original (single writer principle)
|
||||||
|
connectionsREF.lazySet(this, head);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a custom connection to the server.
|
||||||
|
* <p>
|
||||||
|
* This should only be used in situations where there can be DIFFERENT types of connections (such as a 'web-based' connection) and
|
||||||
|
* you want *this* server instance to manage listeners + message dispatch
|
||||||
|
*
|
||||||
|
* @param connection the connection to remove
|
||||||
|
*/
|
||||||
|
void removeConnection(C connection) {
|
||||||
// synchronized is used here to ensure the "single writer principle", and make sure that ONLY one thread at a time can enter this
|
// synchronized is used here to ensure the "single writer principle", and make sure that ONLY one thread at a time can enter this
|
||||||
// section. Because of this, we can have unlimited reader threads all going at the same time, without contention (which is our
|
// section. Because of this, we can have unlimited reader threads all going at the same time, without contention (which is our
|
||||||
// use-case 99% of the time)
|
// use-case 99% of the time)
|
||||||
@ -619,6 +642,7 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a non-modifiable list of active connections. This is extremely slow, and not recommended!
|
* Returns a non-modifiable list of active connections. This is extremely slow, and not recommended!
|
||||||
*/
|
*/
|
||||||
|
@ -70,4 +70,30 @@ class EndPointServer<C extends Connection> extends EndPoint<C> {
|
|||||||
void removeListenerManager(final C connection) {
|
void removeListenerManager(final C connection) {
|
||||||
this.connectionManager.removeListenerManager(connection);
|
this.connectionManager.removeListenerManager(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a custom connection to the server.
|
||||||
|
* <p>
|
||||||
|
* This should only be used in situations where there can be DIFFERENT types of connections (such as a 'web-based' connection) and
|
||||||
|
* you want *this* server instance to manage listeners + message dispatch
|
||||||
|
*
|
||||||
|
* @param connection the connection to add
|
||||||
|
*/
|
||||||
|
public
|
||||||
|
void addConnection(C connection) {
|
||||||
|
connectionManager.addConnection(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a custom connection to the server.
|
||||||
|
* <p>
|
||||||
|
* This should only be used in situations where there can be DIFFERENT types of connections (such as a 'web-based' connection) and
|
||||||
|
* you want *this* server instance to manage listeners + message dispatch
|
||||||
|
*
|
||||||
|
* @param connection the connection to remove
|
||||||
|
*/
|
||||||
|
public
|
||||||
|
void removeConnection(C connection) {
|
||||||
|
connectionManager.addConnection(connection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user