gdamour 2004/06/03 07:39:45
Modified:
sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/network
RemoteNodeJoiner.java NodeServerImpl.java
RemoteNodeJoined.java
RemoteNodeJoinerConnection.java
sandbox/messaging/src/test/org/apache/geronimo/messaging
NodeImplTest.java
sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode
RemoteNode.java RemoteNodeManagerImpl.java
sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote
RemoteUseCaseTest.java
sandbox/messaging/src/test/org/apache/geronimo/messaging/remotenode
MockRemoteNode.java
Added:
sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/admin
JoinRequest.java JoinReply.java
RemoteNodeConnectionCommand.java
Removed:
sandbox/messaging/src/test/org/apache/geronimo/messaging/remotenode/network
NodeServerImplTest.java
ProtocolOutInterceptorTest.java
Log:
Node.join is now a synchronous operation.
Revision Changes Path
1.2 +4 -14
incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/network/RemoteNodeJoiner.java
Index: RemoteNodeJoiner.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/network/RemoteNodeJoiner.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RemoteNodeJoiner.java 11 May 2004 12:06:42 -0000 1.1
+++ RemoteNodeJoiner.java 3 Jun 2004 14:39:44 -0000 1.2
@@ -19,8 +19,6 @@
import java.io.IOException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.messaging.CommunicationException;
import org.apache.geronimo.messaging.NodeInfo;
import org.apache.geronimo.messaging.io.IOContext;
@@ -37,15 +35,8 @@
implements RemoteNode
{
- private static final Log log = LogFactory.getLog(RemoteNodeJoiner.class);
-
private final MessagingTransportFactory connFactory;
- /**
- * Connection to the remote node.
- */
- private RemoteNodeConnection connection;
-
public RemoteNodeJoiner(NodeInfo aNodeInfo, IOContext anIOContext,
MessagingTransportFactory aFactory) {
super(aNodeInfo, anIOContext);
@@ -55,10 +46,9 @@
connFactory = aFactory;
}
- public void connect() throws IOException, CommunicationException {
- connection = connFactory.factoryNodeConnection(nodeInfo, ioContext);
- connection.open();
- addConnection(connection);
+ public RemoteNodeConnection newConnection()
+ throws IOException, CommunicationException {
+ return connFactory.factoryNodeConnection(nodeInfo, ioContext);
}
}
1.3 +6 -8
incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/network/NodeServerImpl.java
Index: NodeServerImpl.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/network/NodeServerImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NodeServerImpl.java 27 May 2004 14:27:32 -0000 1.2
+++ NodeServerImpl.java 3 Jun 2004 14:39:44 -0000 1.3
@@ -25,8 +25,6 @@
import org.apache.geronimo.messaging.CommunicationException;
import org.apache.geronimo.messaging.Msg;
import org.apache.geronimo.messaging.MsgBody;
-import org.apache.geronimo.messaging.MsgHeader;
-import org.apache.geronimo.messaging.MsgHeaderConstants;
import org.apache.geronimo.messaging.NodeInfo;
import org.apache.geronimo.messaging.interceptors.MsgOutInterceptor;
import org.apache.geronimo.messaging.io.IOContext;
@@ -34,6 +32,7 @@
import org.apache.geronimo.messaging.remotenode.RemoteNode;
import org.apache.geronimo.messaging.remotenode.RemoteNodeConnection;
import org.apache.geronimo.messaging.remotenode.RemoteNodeManager;
+import org.apache.geronimo.messaging.remotenode.admin.JoinReply;
import org.apache.geronimo.network.SelectorManager;
import org.apache.geronimo.network.protocol.AcceptableProtocol;
import org.apache.geronimo.network.protocol.AcceptableProtocolStack;
@@ -170,16 +169,15 @@
MsgBody body = aMsg.getBody();
NodeInfo otherNodeInfo = (NodeInfo) body.getContent();
+ JoinReply joinReply = new JoinReply(aMsg);
+ joinReply.execute(connection);
+
RemoteNode remoteNode = manager.findRemoteNode(otherNodeInfo);
if ( null == remoteNode ) {
remoteNode = new RemoteNodeJoined(otherNodeInfo, ioContext);
- manager.registerRemoteNode(remoteNode);
}
remoteNode.addConnection(connection);
-
- Msg msg = aMsg.reply();
- msg.getBody().setContent(Boolean.TRUE);
- connection.getMsgConsumerOut().push(msg);
+ manager.registerRemoteNode(remoteNode);
}
}
1.2 +5 -5
incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/network/RemoteNodeJoined.java
Index: RemoteNodeJoined.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/network/RemoteNodeJoined.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RemoteNodeJoined.java 11 May 2004 12:06:42 -0000 1.1
+++ RemoteNodeJoined.java 3 Jun 2004 14:39:44 -0000 1.2
@@ -17,12 +17,10 @@
package org.apache.geronimo.messaging.remotenode.network;
-import java.io.IOException;
-
-import org.apache.geronimo.messaging.CommunicationException;
import org.apache.geronimo.messaging.NodeInfo;
import org.apache.geronimo.messaging.io.IOContext;
import org.apache.geronimo.messaging.remotenode.RemoteNode;
+import org.apache.geronimo.messaging.remotenode.RemoteNodeConnection;
/**
*
@@ -37,7 +35,9 @@
super(aNodeInfo, anIOContext);
}
- public void connect() throws IOException, CommunicationException {
+ public RemoteNodeConnection newConnection() {
+ throw new UnsupportedOperationException(
+ "A joined node does not create connections");
}
}
1.2 +9 -12
incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/network/RemoteNodeJoinerConnection.java
Index: RemoteNodeJoinerConnection.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/network/RemoteNodeJoinerConnection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RemoteNodeJoinerConnection.java 11 May 2004 12:06:42 -0000 1.1
+++ RemoteNodeJoinerConnection.java 3 Jun 2004 14:39:44 -0000 1.2
@@ -19,8 +19,6 @@
import java.net.InetSocketAddress;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.messaging.NodeInfo;
import org.apache.geronimo.messaging.io.IOContext;
import org.apache.geronimo.messaging.remotenode.RemoteNodeConnection;
@@ -28,6 +26,7 @@
import org.apache.geronimo.network.protocol.BufferProtocol;
import org.apache.geronimo.network.protocol.Protocol;
import org.apache.geronimo.network.protocol.ProtocolException;
+import org.apache.geronimo.network.protocol.ProtocolStack;
import org.apache.geronimo.network.protocol.SocketProtocol;
/**
@@ -39,10 +38,8 @@
implements RemoteNodeConnection
{
- private static final Log log =
LogFactory.getLog(RemoteNodeJoinerConnection.class);
-
/**
- * NodeInfo the remote node.
+ * NodeInfo of the remote node.
*/
private final NodeInfo nodeInfo;
@@ -64,6 +61,8 @@
protected Protocol newProtocol() throws ProtocolException {
String hostName = nodeInfo.getAddress().getHostName();
int port = nodeInfo.getPort();
+
+ ProtocolStack stack = new ProtocolStack();
SocketProtocol socketProtocol = new SocketProtocol();
// TODO configurable.
@@ -71,17 +70,15 @@
socketProtocol.setInterface(new InetSocketAddress(hostName, 0));
socketProtocol.setAddress(new InetSocketAddress(hostName, port));
socketProtocol.setSelectorManager(selectorManager);
+ stack.push(socketProtocol);
BufferProtocol buffpt = new BufferProtocol();
buffpt.setThreadPool(selectorManager.getThreadPool());
-
- socketProtocol.setUpProtocol(buffpt);
- buffpt.setDownProtocol(socketProtocol);
+ stack.push(buffpt);
- socketProtocol.setup();
- buffpt.setup();
+ stack.setup();
- return buffpt;
+ return stack;
}
}
1.2 +5 -9
incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/NodeImplTest.java
Index: NodeImplTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/NodeImplTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NodeImplTest.java 11 May 2004 12:06:41 -0000 1.1
+++ NodeImplTest.java 3 Jun 2004 14:39:44 -0000 1.2
@@ -120,33 +120,29 @@
path = new NodePath(nodeInfo3, nodeInfo4, weight, weight);
topology.addPath(path);
- Thread.sleep(500);
-
node1.setTopology(topology);
node2.setTopology(topology);
node3.setTopology(topology);
node4.setTopology(topology);
-
- Thread.sleep(500);
}
protected void tearDown() throws Exception {
- Thread.sleep(500);
-
endPoint41.doStop();
node4.doStop();
+ ctx4.stop();
node3.doStop();
+ ctx3.stop();
endPoint22.doStop();
endPoint21.doStop();
node2.doStop();
+ ctx2.stop();
endPoint11.doStop();
endPoint21.doStop();
node1.doStop();
-
- Thread.sleep(500);
+ ctx1.stop();
}
public void testMulticast() throws Exception {
1.2 +6 -3
incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/RemoteNode.java
Index: RemoteNode.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/RemoteNode.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RemoteNode.java 11 May 2004 12:06:42 -0000 1.1
+++ RemoteNode.java 3 Jun 2004 14:39:44 -0000 1.2
@@ -40,12 +40,15 @@
public NodeInfo getNodeInfo();
/**
- * Connects to the remote node.
+ * Returns a connection to the remote node.
+ * <BR>
+ * This connection is not opened.
*
* @throws IOException Indicates an I/O problem.
* @throws CommunicationException If a communication can not be
established.
*/
- public void connect() throws IOException, CommunicationException;
+ public RemoteNodeConnection newConnection()
+ throws IOException, CommunicationException;
/**
* Leaves the remote node.
1.3 +11 -18
incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/RemoteNodeManagerImpl.java
Index: RemoteNodeManagerImpl.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/RemoteNodeManagerImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RemoteNodeManagerImpl.java 27 May 2004 14:27:32 -0000 1.2
+++ RemoteNodeManagerImpl.java 3 Jun 2004 14:39:44 -0000 1.3
@@ -37,6 +37,7 @@
import org.apache.geronimo.messaging.RequestSender;
import org.apache.geronimo.messaging.interceptors.MsgOutInterceptor;
import org.apache.geronimo.messaging.io.IOContext;
+import org.apache.geronimo.messaging.remotenode.admin.JoinRequest;
/**
* RemoteNode implementation.
@@ -162,27 +163,19 @@
return remoteNode;
}
remoteNode = factory.factoryNode(aNodeInfo, ioContext);
+ RemoteNodeConnection connection;
try {
- remoteNode.connect();
+ connection = remoteNode.newConnection();
+ connection.open();
} catch (IOException e) {
throw new NodeException("Can not reach " + aNodeInfo, e);
} catch (CommunicationException e) {
throw new NodeException("Can not reach " + aNodeInfo, e);
}
- Msg msg = new Msg();
- MsgHeader header = msg.getHeader();
- header.addHeader(MsgHeaderConstants.SRC_NODE, nodeInfo);
- header.addHeader(MsgHeaderConstants.DEST_NODE, aNodeInfo);
-
- // Only set to comply with a valid request.
- header.addHeader(MsgHeaderConstants.DEST_NODES, aNodeInfo);
- header.addHeader(MsgHeaderConstants.SRC_ENDPOINT, "");
- header.addHeader(MsgHeaderConstants.CORRELATION_ID,
- new RequestSender.RequestID(new Integer(0)));
-
- msg.getBody().setContent(nodeInfo);
- remoteNode.getMsgConsumerOut().push(msg);
-
+ JoinRequest joinRequest = new JoinRequest(nodeInfo, aNodeInfo);
+ joinRequest.execute(connection);
+
+ remoteNode.addConnection(connection);
registerRemoteNode(remoteNode);
}
return remoteNode;
@@ -271,13 +264,13 @@
header2.getHeader(MsgHeaderConstants.SRC_NODE);
path = topology.getPath(src, target);
if ( null == path ) {
- throw new RuntimeException("{" + target +
+ throw new CommunicationException("{" + target +
"} is not reachable by {" + src + "}");
}
NodeInfo tmpNode = path[0];
RemoteNode remoteNode = findRemoteNode(tmpNode);
if ( null == remoteNode ) {
- throw new RuntimeException("{" + target +
+ throw new CommunicationException("{" + target +
"} is not reachable by {" + src + "}");
}
out = remoteNode.getMsgConsumerOut();
1.1
incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/admin/JoinRequest.java
Index: JoinRequest.java
===================================================================
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.messaging.remotenode.admin;
import java.lang.reflect.InvocationTargetException;
import org.apache.geronimo.messaging.CommunicationException;
import org.apache.geronimo.messaging.Msg;
import org.apache.geronimo.messaging.MsgHeader;
import org.apache.geronimo.messaging.MsgHeaderConstants;
import org.apache.geronimo.messaging.NodeInfo;
import org.apache.geronimo.messaging.RequestSender;
import org.apache.geronimo.messaging.interceptors.MsgOutInterceptor;
import org.apache.geronimo.messaging.remotenode.RemoteNodeConnection;
import EDU.oswego.cs.dl.util.concurrent.FutureResult;
import EDU.oswego.cs.dl.util.concurrent.TimeoutException;
/**
* Join request.
*
* @version $Revision: 1.1 $ $Date: 2004/06/03 14:39:44 $
*/
public class JoinRequest
implements RemoteNodeConnectionCommand
{
/**
* Node which initiates the join command.
*/
private final NodeInfo joiner;
/**
* Target of the join command.
*/
private final NodeInfo joined;
/**
* @param aJoiner Node which initiates the join command.
* @param aJoined Target of the join command.
*/
public JoinRequest(NodeInfo aJoiner, NodeInfo aJoined) {
if ( null == aJoiner ) {
throw new IllegalArgumentException("Joiner is required");
} else if ( null == aJoined ) {
throw new IllegalArgumentException("Joined is required");
}
joiner = aJoiner;
joined = aJoined;
}
public void execute(RemoteNodeConnection aConnection) {
Msg msg = new Msg();
MsgHeader header = msg.getHeader();
header.addHeader(MsgHeaderConstants.SRC_NODE, joiner);
header.addHeader(MsgHeaderConstants.DEST_NODE, joined);
// Only set to comply with a valid request.
header.addHeader(MsgHeaderConstants.DEST_NODES, joined);
header.addHeader(MsgHeaderConstants.SRC_ENDPOINT, "");
header.addHeader(MsgHeaderConstants.CORRELATION_ID,
new RequestSender.RequestID(new Integer(0)));
msg.getBody().setContent(joiner);
final FutureResult result = new FutureResult();
aConnection.setMsgProducerOut(new MsgOutInterceptor() {
public void push(Msg aMsg) {
result.set(aMsg);
}
});
aConnection.getMsgConsumerOut().push(msg);
Msg reply;
try {
// waits 3 seconds for a reply.
reply = (Msg) result.get();
// reply = (Msg) result.timedGet(3000);
} catch (TimeoutException e) {
throw new CommunicationException("Join request submitted by " +
joiner + " to " + joined + " has timed out.");
} catch (InterruptedException e) {
throw new CommunicationException(e);
} catch (InvocationTargetException e) {
throw new CommunicationException(e);
}
Boolean isOK = (Boolean) reply.getBody().getContent();
if ( Boolean.FALSE == isOK ) {
throw new CommunicationException(joined + " has refused the " +
"join request submitted by " + joiner);
}
}
}
1.1
incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/admin/JoinReply.java
Index: JoinReply.java
===================================================================
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.messaging.remotenode.admin;
import org.apache.geronimo.messaging.Msg;
import org.apache.geronimo.messaging.remotenode.RemoteNodeConnection;
/**
* Join command reply.
*
* @version $Revision: 1.1 $ $Date: 2004/06/03 14:39:44 $
*/
public class JoinReply
implements RemoteNodeConnectionCommand
{
/**
* Join request.
*/
private final Msg request;
/**
* @param aRequest Join request.
*/
public JoinReply(Msg aRequest) {
request = aRequest;
}
public void execute(RemoteNodeConnection aConnection) {
Msg msg = request.reply();
msg.getBody().setContent(Boolean.TRUE);
aConnection.getMsgConsumerOut().push(msg);
}
}
1.1
incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/remotenode/admin/RemoteNodeConnectionCommand.java
Index: RemoteNodeConnectionCommand.java
===================================================================
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.messaging.remotenode.admin;
import org.apache.geronimo.messaging.remotenode.RemoteNodeConnection;
/**
* Command for a RemoteNodeConnection.
*
* @version $Revision: 1.1 $ $Date: 2004/06/03 14:39:44 $
*/
public interface RemoteNodeConnectionCommand
{
/**
* Executes a command on the specified connection.
*
* @param aConnection Connection.
*/
public void execute(RemoteNodeConnection aConnection);
}
1.7 +4 -7
incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote/RemoteUseCaseTest.java
Index: RemoteUseCaseTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote/RemoteUseCaseTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RemoteUseCaseTest.java 20 May 2004 13:37:11 -0000 1.6
+++ RemoteUseCaseTest.java 3 Jun 2004 14:39:45 -0000 1.7
@@ -101,19 +101,16 @@
NodePath path = new NodePath(nodeInfo1, nodeInfo2, weight, weight);
topology.addPath(path);
- Thread.sleep(500);
-
node1.setTopology(topology);
node2.setTopology(topology);
-
- Thread.sleep(500);
}
protected void tearDown() throws Exception {
- Thread.sleep(500);
-
node2.doStop();
+ ctx2.stop();
+
node1.doStop();
+ ctx1.stop();
}
private static class ProtocolContext {
1.2 +3 -2
incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/remotenode/MockRemoteNode.java
Index: MockRemoteNode.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/remotenode/MockRemoteNode.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MockRemoteNode.java 11 May 2004 12:06:43 -0000 1.1
+++ MockRemoteNode.java 3 Jun 2004 14:39:45 -0000 1.2
@@ -52,7 +52,8 @@
public void setTopology(NodeTopology aTopology) {
}
- public void connect() throws IOException, CommunicationException {
+ public RemoteNodeConnection newConnection() throws IOException,
CommunicationException {
+ return null;
}
public void leave() throws IOException, CommunicationException {