Author: david.lloyd(a)jboss.com
Date: 2008-11-06 16:26:46 -0500 (Thu, 06 Nov 2008)
New Revision: 4649
Modified:
remoting3/trunk/api/src/main/java/org/jboss/remoting/ServiceListener.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
Log:
More flexible and future-proof service registration listener API
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/ServiceListener.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/ServiceListener.java 2008-11-05
09:49:49 UTC (rev 4648)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/ServiceListener.java 2008-11-06
21:26:46 UTC (rev 4649)
@@ -30,27 +30,79 @@
public interface ServiceListener {
/**
- * Receive notification that a local service was added. To receive a notification
when it is closed, register a
- * close handler on the provided {@code requestHandlerSource} parameter.
+ * Receive notification that a service was registered.
*
* @param listenerHandle the handle to this listener
- * @param serviceType the service type string
- * @param groupName the group name string
- * @param requestHandlerSource the request handler source
+ * @param info the servce information
*/
- void localServiceCreated(SimpleCloseable listenerHandle, String serviceType, String
groupName, RequestHandlerSource requestHandlerSource);
+ void serviceRegistered(SimpleCloseable listenerHandle, ServiceInfo info);
/**
- * Receive notification that a remote service was registered. To receive a
notification when it is unregistered, register a
- * close handler on the provided {@code handle} parameter.
- *
- * @param listenerHandle the handle to this listener
- * @param endpointName the remote endpoint name
- * @param serviceType the service type string
- * @param groupName the group name string
- * @param metric the metric value
- * @param requestHandlerSource the request handler source
- * @param handle the handle to the registration
+ *
*/
- void remoteServiceRegistered(SimpleCloseable listenerHandle, String endpointName,
String serviceType, String groupName, int metric, RequestHandlerSource
requestHandlerSource, SimpleCloseable handle);
+ final class ServiceInfo {
+ private String endpointName;
+ private String serviceType;
+ private String groupName;
+ private boolean remote;
+ private int metric;
+ private RequestHandlerSource requestHandlerSource;
+ private SimpleCloseable registrationHandle;
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(final String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public void setGroupName(final String groupName) {
+ this.groupName = groupName;
+ }
+
+ public int getMetric() {
+ return metric;
+ }
+
+ public void setMetric(final int metric) {
+ this.metric = metric;
+ }
+
+ public RequestHandlerSource getRequestHandlerSource() {
+ return requestHandlerSource;
+ }
+
+ public void setRequestHandlerSource(final RequestHandlerSource
requestHandlerSource) {
+ this.requestHandlerSource = requestHandlerSource;
+ }
+
+ public SimpleCloseable getRegistrationHandle() {
+ return registrationHandle;
+ }
+
+ public void setRegistrationHandle(final SimpleCloseable registrationHandle) {
+ this.registrationHandle = registrationHandle;
+ }
+
+ public String getEndpointName() {
+ return endpointName;
+ }
+
+ public void setEndpointName(final String endpointName) {
+ this.endpointName = endpointName;
+ }
+
+ public boolean isRemote() {
+ return remote;
+ }
+
+ public void setRemote(final boolean remote) {
+ this.remote = remote;
+ }
+ }
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java 2008-11-05
09:49:49 UTC (rev 4648)
+++
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java 2008-11-06
21:26:46 UTC (rev 4649)
@@ -203,7 +203,15 @@
for (final ServiceListenerRegistration slr : serviceListenerMap.values()) {
final ServiceListener listener = slr.getServiceListener();
try {
- listener.localServiceCreated(slr.handle, serviceType, groupName,
localRequestHandlerSource);
+ final ServiceListener.ServiceInfo serviceInfo = new
ServiceListener.ServiceInfo();
+ serviceInfo.setEndpointName(name);
+ serviceInfo.setGroupName(groupName);
+ serviceInfo.setServiceType(serviceType);
+ serviceInfo.setMetric(metric);
+ serviceInfo.setRegistrationHandle(newHandle);
+ serviceInfo.setRemote(false);
+ serviceInfo.setRequestHandlerSource(localRequestHandlerSource);
+ listener.serviceRegistered(slr.handle, serviceInfo);
} catch (Throwable t) {
logListenerError(t);
}
@@ -287,12 +295,11 @@
if (size == 0) {
final FutureClientSource<I, O> futureClientSource = new
FutureClientSource<I, O>();
final SimpleCloseable listenerHandle = addServiceListener(new
ServiceListener() {
-
- public void localServiceCreated(final SimpleCloseable listenerHandle,
final String addedServiceType, final String addedGroupName, final RequestHandlerSource
requestHandlerSource) {
- remoteServiceRegistered(listenerHandle, name, addedServiceType,
addedGroupName, 0, requestHandlerSource, null);
- }
-
- public void remoteServiceRegistered(final SimpleCloseable
listenerHandle, final String addedEndpointName, final String addedServiceType, final
String addedGroupName, final int metric, final RequestHandlerSource requestHandlerSource,
final SimpleCloseable handle) {
+ public void serviceRegistered(final SimpleCloseable listenerHandle,
final ServiceInfo info) {
+ final String addedEndpointName = info.getEndpointName();
+ final String addedServiceType = info.getServiceType();
+ final String addedGroupName = info.getGroupName();
+ final RequestHandlerSource requestHandlerSource =
info.getRequestHandlerSource();
if (endpointName != null && endpointName.length() > 0
&& !endpointName.equals(addedEndpointName)) {
// no match
return;
@@ -385,7 +392,15 @@
for (final ServiceListenerRegistration slr : serviceListenerMap.values()) {
final ServiceListener listener = slr.getServiceListener();
try {
- listener.remoteServiceRegistered(slr.handle, endpointName,
serviceType, groupName, metric, handlerSource, newHandle);
+ final ServiceListener.ServiceInfo info = new
ServiceListener.ServiceInfo();
+ info.setEndpointName(endpointName);
+ info.setGroupName(groupName);
+ info.setMetric(metric);
+ info.setRegistrationHandle(newHandle);
+ info.setRemote(true);
+ info.setRequestHandlerSource(handlerSource);
+ info.setServiceType(serviceType);
+ listener.serviceRegistered(slr.handle, info);
} catch (Throwable t) {
logListenerError(t);
}
@@ -414,11 +429,15 @@
if (! onlyNew) {
for (final ServiceRegistration reg : serviceRegistrations) {
try {
- if (reg.isRemote()) { // x is remote
- serviceListener.remoteServiceRegistered(handle,
reg.getEndpointName(), reg.getServiceType(), reg.getGroupName(), reg.getMetric(),
reg.getHandlerSource(), reg.getHandle());
- } else { // x is local
- serviceListener.localServiceCreated(handle,
reg.getServiceType(), reg.getGroupName(), reg.getHandlerSource());
- }
+ final ServiceListener.ServiceInfo info = new
ServiceListener.ServiceInfo();
+ info.setEndpointName(reg.getEndpointName());
+ info.setGroupName(reg.getGroupName());
+ info.setMetric(reg.getMetric());
+ info.setRegistrationHandle(reg.getHandle());
+ info.setRemote(reg.isRemote());
+ info.setRequestHandlerSource(reg.getHandlerSource());
+ info.setServiceType(reg.getServiceType());
+ serviceListener.serviceRegistered(handle, info);
} catch (Throwable t) {
logListenerError(t);
}
Modified:
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
===================================================================
---
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java 2008-11-05
09:49:49 UTC (rev 4648)
+++
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java 2008-11-06
21:26:46 UTC (rev 4649)
@@ -65,7 +65,7 @@
*
* @param endpoint the endpoint
* @param configuration the configuration
- * @param channelSource the XNIO channel source to use to establish the connection
@param allocator the buffer allocator to use
+ * @param channelSource the XNIO channel source to use to establish the connection
* @return a handle which may be used to close the connection
* @throws IOException if an error occurs
*/