Author: david.lloyd(a)jboss.com
Date: 2008-03-27 01:09:50 -0400 (Thu, 27 Mar 2008)
New Revision: 3794
Added:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealContextSource.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ContextSourceMarker.java
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealContext.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundContext.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
Log:
Adding service forwarding support (finally)
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealContext.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealContext.java 2008-03-27
04:49:41 UTC (rev 3793)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealContext.java 2008-03-27
05:09:50 UTC (rev 3794)
@@ -6,8 +6,7 @@
/**
*
*/
-public abstract class AbstractRealContext<I, O> implements Context<I, O>,
Serializable {
- private static final long serialVersionUID = 1L;
+public abstract class AbstractRealContext<I, O> implements Context<I, O> {
private ContextServer<I,O> contextServer;
@@ -18,10 +17,6 @@
this.contextServer = contextServer;
}
- private Object writeReplace() {
- return contextServer;
- }
-
protected ContextServer<I, O> getContextServer() {
return contextServer;
}
Added:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealContextSource.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealContextSource.java
(rev 0)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractRealContextSource.java 2008-03-27
05:09:50 UTC (rev 3794)
@@ -0,0 +1,21 @@
+package org.jboss.cx.remoting.core;
+
+import org.jboss.cx.remoting.ContextSource;
+
+/**
+ *
+ */
+public abstract class AbstractRealContextSource<I, O> implements
ContextSource<I, O> {
+ private ServiceServer<I, O> serviceServer;
+
+ protected AbstractRealContextSource(final ServiceServer<I, O> serviceServer) {
+ if (serviceServer == null) {
+ throw new NullPointerException("serviceServer is null");
+ }
+ this.serviceServer = serviceServer;
+ }
+
+ public ServiceServer<I, O> getServiceServer() {
+ return serviceServer;
+ }
+}
Copied:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ContextSourceMarker.java
(from rev 3636,
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ContextMarker.java)
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ContextSourceMarker.java
(rev 0)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ContextSourceMarker.java 2008-03-27
05:09:50 UTC (rev 3794)
@@ -0,0 +1,29 @@
+package org.jboss.cx.remoting.core;
+
+import org.jboss.cx.remoting.spi.protocol.ContextIdentifier;
+import org.jboss.cx.remoting.spi.protocol.ServiceIdentifier;
+import java.io.Serializable;
+
+/**
+ *
+ */
+public final class ContextSourceMarker implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private ServiceIdentifier serviceIdentifier;
+
+ public ContextSourceMarker() {
+ }
+
+ public ContextSourceMarker(final ServiceIdentifier serviceIdentifier) {
+ this.serviceIdentifier = serviceIdentifier;
+ }
+
+ public ServiceIdentifier getServiceIdentifier() {
+ return serviceIdentifier;
+ }
+
+ public void setServiceIdentifier(final ServiceIdentifier serviceIdentifier) {
+ this.serviceIdentifier = serviceIdentifier;
+ }
+}
\ No newline at end of file
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundContext.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundContext.java 2008-03-27
04:49:41 UTC (rev 3793)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundContext.java 2008-03-27
05:09:50 UTC (rev 3794)
@@ -72,9 +72,7 @@
}
}
- @SuppressWarnings
({"SerializableInnerClassWithNonSerializableOuterClass"})
- public final class UserContext extends AbstractRealContext<I, O> implements
Serializable {
- private static final long serialVersionUID = 1L;
+ public final class UserContext extends AbstractRealContext<I, O> {
private UserContext() {
super(contextServer);
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java 2008-03-27
04:49:41 UTC (rev 3793)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java 2008-03-27
05:09:50 UTC (rev 3794)
@@ -55,17 +55,13 @@
}
@SuppressWarnings
({"SerializableInnerClassWithNonSerializableOuterClass"})
- public final class UserContextSource implements ContextSource<I, O>,
Serializable {
- private static final long serialVersionUID = 1L;
-
- private Object writeReplace() {
- return serviceServer;
+ public final class UserContextSource extends AbstractRealContextSource<I, O> {
+ protected UserContextSource() {
+ super(serviceServer);
}
public void close() {
// todo ...
-
- // todo: is it better to close all child contexts, or let them continue on
independently?
}
public void closeImmediate() throws RemotingException {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-03-27
04:49:41 UTC (rev 3793)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-03-27
05:09:50 UTC (rev 3794)
@@ -547,7 +547,7 @@
public void close() throws IOException {
target.close();
}
- });
+ }, true);
if (target == null) {
throw new NullPointerException("target is null");
}
@@ -581,14 +581,6 @@
return target.getBytesWritten();
}
- protected final void writeObjectOverride(Object obj) throws IOException {
- if (obj instanceof AbstractRealContext) {
- super.writeObjectOverride(doContextReplace(((AbstractRealContext<?,
?>)obj).getContextServer()));
- } else {
- super.writeObjectOverride(obj);
- }
- }
-
private final <I, O> ContextMarker doContextReplace(ContextServer<I,
O> contextServer) throws IOException {
final ContextIdentifier contextIdentifier = protocolHandler.openContext();
final ProtocolContextClientImpl<I, O> contextClient = new
ProtocolContextClientImpl<I, O>(contextIdentifier);
@@ -596,8 +588,20 @@
return new ContextMarker(contextIdentifier);
}
+ private final <I, O> ContextSourceMarker
doContextSourceReplace(ServiceServer<I, O> serviceServer) throws IOException {
+ final ServiceIdentifier serviceIdentifier = protocolHandler.openService();
+ final ProtocolServiceClientImpl serviceClient = new
ProtocolServiceClientImpl(serviceIdentifier);
+ new ServerServicePair<I, O>(serviceClient, serviceServer);
+ return new ContextSourceMarker(serviceIdentifier);
+ }
+
protected Object replaceObject(Object obj) throws IOException {
final Object testObject = super.replaceObject(obj);
+ if (testObject instanceof AbstractRealContext) {
+ return doContextReplace(((AbstractRealContext<?, ?>)
obj).getContextServer());
+ } else if (testObject instanceof AbstractRealContextSource) {
+ return doContextSourceReplace(((AbstractRealContextSource<?, ?>)
obj).getServiceServer());
+ }
for (StreamDetector detector : streamDetectors) {
final StreamSerializerFactory factory =
detector.detectStream(testObject);
if (factory != null) {
@@ -614,7 +618,6 @@
return new StreamMarker(factory.getClass(), streamIdentifier);
}
}
- log.trace("Writing object: %s", testObject);
return testObject;
}
}