|
From: <ian...@us...> - 2007-11-09 00:10:45
|
Revision: 566
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=566&view=rev
Author: iansmith
Date: 2007-11-08 16:10:49 -0800 (Thu, 08 Nov 2007)
Log Message:
-----------
Whew. It's in, comet support is now turned on. This should have no effect on coders or users, except that we can now pass quietly through firewalls.
Modified Paths:
--------------
maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/servlet/AbstractResourceServlet.java
maven/trunk/ogoglio-common/pom.xml
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIDescriptor.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/MeasPerfClient.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/Message.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/SenderQueue.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/TCPChannel.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/TCPMessageReader.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProto.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProtoFactory.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometClient.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometProto.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/Locator.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/SimpleSocketAsync.java
maven/trunk/ogoglio-integration-test/pom.xml
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/AsyncClientReady.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/AsyncProtoServerFactory.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/CometChannelManager.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/CometServlet.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/MeasPerfServer.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/NetworkChannelServer.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/SimpleSocketAsyncServer.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/Sim.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SimMessageHandler.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SpaceSimulator.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/site/SimServlet.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/MessageProxy.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/SpaceServlet.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/WebappServletBase.java
maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ViewerApplet.java
Added Paths:
-----------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/LineOrientedCRLFSocket.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/NegativeReadValueException.java
maven/trunk/ogoglio-integration-test/src/main/java/com/
maven/trunk/ogoglio-integration-test/src/main/java/com/ogoglio/
maven/trunk/ogoglio-integration-test/src/main/java/com/ogoglio/amazon/
maven/trunk/ogoglio-integration-test/src/main/java/com/ogoglio/amazon/test/
maven/trunk/ogoglio-integration-test/src/main/java/com/ogoglio/amazon/test/CometTest.java
maven/trunk/ogoglio-integration-test/src/main/scripts/
maven/trunk/ogoglio-integration-test/src/main/scripts/testComet
Removed Paths:
-------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProtoInfo.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometInfo.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/SimpleSocketInfo.java
Modified: maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/servlet/AbstractResourceServlet.java
===================================================================
--- maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/servlet/AbstractResourceServlet.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/servlet/AbstractResourceServlet.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -224,7 +224,6 @@
String headerName = (String) headerNames.nextElement();
connection.setRequestProperty(headerName, request.getHeader(headerName));
}
-
if ("POST".equals(method)) {
connection.setDoOutput(true);
InputStream requestInput = request.getInputStream();
Modified: maven/trunk/ogoglio-common/pom.xml
===================================================================
--- maven/trunk/ogoglio-common/pom.xml 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/pom.xml 2007-11-09 00:10:49 UTC (rev 566)
@@ -50,6 +50,7 @@
<artifactId>commons-logging</artifactId>
<version>1.1</version>
</dependency>
+
</dependencies>
</project>
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -17,6 +17,8 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.Vector;
import java.util.zip.ZipInputStream;
@@ -75,8 +77,12 @@
private boolean cleanedUp = false;
+ private static final long HEARTBEAT_INTERVAL=5000L;
+
private BodyDataProvider bodyDataProvider = new NetworkBodyDataProvider();
+ private Timer heartbeatTimer=null;
+
public SpaceClient(long spaceID, URI serviceURI, String authCookie, Listener listener) throws IOException {
ArgumentUtils.assertNotNegative(spaceID);
ArgumentUtils.assertNotNull(serviceURI);
@@ -105,8 +111,7 @@
space = new Space(this, spaceDoc.getSpaceID(), spaceDoc.getDisplayName(), spaceDoc.getOwnerUsername(), spaceDoc.getDisplaySea(), spaceDoc.getSeaLevel());
//create the event channel and start queuing events
- Object selector = AsyncProtoFactory.getDefaultInfo().getProxySpecificSelector();
- messageChannel = new TCPChannel(AsyncProtoFactory.getDefaultClient(serviceURI.getHost(), selector), messenger, true, new ChannelListener(), true);
+ messageChannel = new TCPChannel(AsyncProtoFactory.getDefaultClient(descriptor, true), messenger, true, new ChannelListener(), true, "space-client");
messenger.authenticate(authCookie);
long startWait = System.currentTimeMillis();
@@ -128,6 +133,11 @@
}
}
+ //this download can take longer than the timeout of our connection, so force heartbeats
+ //before we start doing all this
+ heartbeatTimer = new Timer("Heartbeat Client", true);
+ heartbeatTimer.schedule(new HeartbeatTimer(), 0L, HEARTBEAT_INTERVAL);
+
ThingDocument[] thingDocs = spaceDoc.getThingDocuments();
for (int i = 0; i < thingDocs.length; i++) {
Template template = space.getTemplate(thingDocs[i].getTemplateID());
@@ -684,6 +694,15 @@
messageChannel.cleanup();
waitingMessages.clear();
}
+
+ public void heartbeat() throws IOException {
+ Message message = new Message(messageChannel.getLocalLocator(), messageChannel.getRemoteLocator(), space.getSpaceID(), new PayloadFactory.HeartbeatPayload());
+ try {
+ messageChannel.sendMessage(message);
+ } catch (NoSuchDestinationException e) {
+ throw new IOException("Could not send heartbeat message");
+ }
+ }
}
private class ChannelListener implements TCPChannel.Listener {
@@ -732,7 +751,9 @@
messageChannel.sendMessage(new Message(messageChannel.getLocalLocator(), messageChannel.getRemoteLocator(), space.getSpaceID(), new PayloadFactory.LogoutPayload(accountDoc.getUsername())));
} catch (Exception e) {
}
-
+ if (heartbeatTimer!=null) { //there is a race condition at startup that makes this necessary
+ heartbeatTimer.cancel();
+ }
messenger.cleanup();
}
@@ -757,7 +778,7 @@
public ZipInputStream getBodyData(long bodyDataID) {
try {
- if(bodyDataID == -1){
+ if (bodyDataID == -1) {
return webClient.getBodyData(WebConstants.GUEST_BODY_FILE_NAME);
} else {
BodyDataDocument dataDoc = webClient.getBodyDataDocument(bodyDataID);
@@ -803,4 +824,14 @@
}
+ private class HeartbeatTimer extends TimerTask {
+ public void run() {
+ try {
+ messenger.heartbeat();
+ } catch (IOException e) {
+ Log.error("Unable to send heartbeat message, IOException:"+e.getMessage());
+ }
+ }
+ }
+
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIDescriptor.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIDescriptor.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIDescriptor.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -3,6 +3,8 @@
import java.io.IOException;
import java.net.URI;
+import com.ogoglio.message.proto.AsyncProto;
+import com.ogoglio.message.proto.AsyncProtoFactory;
import com.ogoglio.util.ArgumentUtils;
import com.ogoglio.util.WebConstants;
@@ -181,4 +183,20 @@
public URI getServiceStateURI() {
return WebAPIUtil.appendToURI(getSpacesURI(), "state/");
}
+
+ public URI getCometProxyURI() {
+ return WebAPIUtil.appendToURI(serviceURI, "comet/"+getCometProxyPath());
+ }
+
+ public URI getCometSimURI() {
+ return WebAPIUtil.appendToURI(serviceURI, "comet/"+getCometSimPath());
+ }
+
+ public String getCometProxyPath() {
+ return "proxy";
+ }
+
+ public String getCometSimPath() {
+ return "sim";
+ }
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/MeasPerfClient.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/MeasPerfClient.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/MeasPerfClient.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -39,7 +39,7 @@
try {
for (int i = 0; i < n; ++i) {
// AsyncProto proto=AsyncProtoFactory.getDefaultClient(argv[1], AsyncProtoFactory.getDefaultInfo().getSimSpecificSelector());
- AsyncProto proto=AsyncProtoFactory.getDefaultClient(argv[1], "/fart/poop");
+ AsyncProto proto=null;/*AsyncProtoFactory.getDefaultClient(argv[1], "/fart/poop");*/
Thread t =new MeasPerfClient(proto);
t.start();
try {
@@ -48,14 +48,14 @@
e.printStackTrace();
}
}
- } catch (IOException e) {
+ } catch (Exception e) {
e.printStackTrace();
}
}
public MeasPerfClient(AsyncProto proto) {
System.out.println("FOUND A CLIENT PROTO:"+(proto!=null));
- channel = new TCPChannel(proto,this,false,this,true);
+ channel = new TCPChannel(proto,this,false,this,true,"measure-perf-client");
}
public void run() {
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/Message.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/Message.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/Message.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -21,7 +21,7 @@
public class Message {
- private static final String MESSAGE = "Message";
+ public static final String MESSAGE = "Message";
private static final String PROXY = "proxy";
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/SenderQueue.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/SenderQueue.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/SenderQueue.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -39,7 +39,9 @@
}
}
- public void start() {
+ public void start(String debugInfo) {
+ senderThread.setName("sender-thread-"+debugInfo+"-"+senderThread.getId());
+ //Log.info("Launching thread "+senderThread.getName());
senderThread.start();
}
@@ -62,8 +64,7 @@
clientProto.sendMessage(command.toString(),messageString);
} catch (IOException e) {
if (!cleaned) {
- e.printStackTrace();
- throw new IllegalStateException("Error writing " + message);
+ throw new IllegalStateException("Error writing to client:" + message);
}
}
}
@@ -80,8 +81,8 @@
Message message = (Message) messageQueue.dequeue();
unsafeSendMessage(message);
} catch (Throwable e) {
- Log.error("Could not send message", e);
- break;
+ //Log.error("Could not send message [aborting thread:"+Thread.currentThread().getName()+"]:"+ e.getClass().getName()+":"+e.getMessage());
+ cleaned=true;
}
}
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/TCPChannel.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/TCPChannel.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/TCPChannel.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -32,7 +32,7 @@
private SenderQueue senderQueue = null;
- //private MessageHandler messageHandler = null;
+ private MessageHandler messageHandler = null;
//private boolean cleaned = false;
@@ -41,7 +41,8 @@
private boolean ensureOrigin = false;
public TCPChannel(AsyncProto proto, MessageHandler message_handler, boolean ensureOrigin,
- Listener listener, boolean needAReaderThread) {
+ Listener listener, boolean needAReaderThread, String debugInfo) {
+
this.clientProto= proto;
//remoteHostName = clientProto.getRemoteAddress().getAddress().getHostAddress();
//remoteHostPort = clientProto.getRemoteAddress().getPort();
@@ -57,21 +58,21 @@
// TODO Don't spand two threads for each socket! No effing way!
senderQueue = new SenderQueue(clientProto, 1000); //TODO what should the max queue size be?
- senderQueue.start();
+ senderQueue.start(debugInfo);
//this is a wee bit hairy. all clients need a reader thread. servers need a reader
//thread depending on their protocol.
- Log.info("Comet got into a TCP channel:"+needAReaderThread);
if (needAReaderThread) {
readerThread = new TCPMessageReader(clientProto, message_handler, this);
+ readerThread.setName("tcp-reader-"+debugInfo+"-"+readerThread.getId());
+ //Log.info("Starting reader thread:"+readerThread.getName());
readerThread.start();
}
-
+ this.messageHandler=message_handler;
+
}
-
-
public void clientReady(AsyncProto newlyConnectedProto) {
Log.info("Client connected from: "+newlyConnectedProto.getRemoteLocator());
}
@@ -112,7 +113,7 @@
throw new NoSuchDestinationException("Passed a message to a TCPChannel with the wrong proxy: " + message.getProxy());
}
} else if (!message.getDestination().equals(clientProto.getRemoteLocator())){
- throw new NoSuchDestinationException("Passed a message to a TCPChannel with the wrong destination: " + message.getDestination());
+ throw new NoSuchDestinationException("Passed a message to a TCPChannel with the wrong destination: " + message.getDestination() + " but should be " + clientProto.getRemoteLocator());
}
try {
@@ -137,4 +138,7 @@
public boolean ensureOrigin() {
return ensureOrigin;
}
+ public MessageHandler getMessageHandler() {
+ return messageHandler;
+ }
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/TCPMessageReader.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/TCPMessageReader.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/TCPMessageReader.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -17,6 +17,7 @@
import java.io.IOException;
import com.ogoglio.message.proto.AsyncProto;
+import com.ogoglio.message.proto.NegativeReadValueException;
import com.ogoglio.util.Log;
public class TCPMessageReader extends Thread {
@@ -71,39 +72,38 @@
public void run() {
try {
- Command command = new Command();
while (!cleaned) {
- String commandLine = clientProto.readLine();
- if (cleaned) {
- return;//somebody shut us down during our wait
+ String msg=clientProto.readLine();
+ if (msg!=null) {
+ //Log.info("TCP Message Reader:"+msg);
+ Message message = Message.parseMessage(msg);
+ if (channel.ensureOrigin()) {
+ message.setOrigin(clientProto.getRemoteLocator());
+ //message.getOrigin().setHost(remoteHostName);
+ //message.getOrigin().setPort(remotePort);
+ }
+ try {
+ messageHandler.handleMessage(message, channel);
+ } catch (Throwable e) {
+ Log.error("Error handling our message",e);
+ e.printStackTrace();
+ }
}
- if (commandLine==null) {
- channel.socketClosed(); //other side went bye-bye
- return;
- }
- command.reset(commandLine);
- String msg = clientProto.readString(command.getMessageLength());
- Message message = Message.parseMessage(msg);
- if (channel.ensureOrigin()) {
- message.setOrigin(clientProto.getRemoteLocator());
- //message.getOrigin().setHost(remoteHostName);
- //message.getOrigin().setPort(remotePort);
- }
- try {
- messageHandler.handleMessage(message, channel);
- } catch (Throwable e) {
- Log.error("Error handling message",e);
- e.printStackTrace();
- }
}
+ } catch (NegativeReadValueException e) {
+ //Log.info("Negative value from read, assuming server closed connection!");
+ channel.socketClosed();
+ cleaned=true;
} catch (Exception e) {
if (!cleaned) {
e.printStackTrace();
}
}
if (!cleaned) {
- Log.warn("Unclean client socket listener thread exiting");
+ Log.warn("Unclean client socket listener thread exiting:"+Thread.currentThread().getName());
channel.socketClosed();
+ } else {
+ //Log.info("Cleaned up and exiting TCPMessageReader thread:"+Thread.currentThread().getName());
}
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProto.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProto.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProto.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -1,7 +1,6 @@
package com.ogoglio.message.proto;
import java.io.IOException;
-import java.net.InetSocketAddress;
/**
* This class represents the notion of a protocol that can be sent over a socket. The
@@ -30,17 +29,9 @@
* Pump out a message with a given command header.
*/
public void sendMessage(String command, String message) throws IOException;
- /**
- * Read in a line terminated by CRLF. If the socket gets closed we return null. We return
- * "" if the line was empty. IOException means something really unexpected happened.
- */
+ //returns the next fully ready message or null
public String readLine() throws IOException;
/**
- * Read in a string that is known to be a given number of bytes. Again, we return null if
- * the socket closes but "" for a zero length string. IOException means something bad happened.
- */
- public String readString(int length) throws IOException;
- /**
* Insure that we are ready for writing to the output.It is required this be called before
* attempting to send.
* @throws IOException
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProtoFactory.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProtoFactory.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProtoFactory.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -1,7 +1,11 @@
package com.ogoglio.message.proto;
import java.io.IOException;
+import java.net.Socket;
+import java.net.URI;
+import com.ogoglio.client.WebAPIDescriptor;
+
/**
* This is a factory for other classes to get a handle on our async protocol handler and so
* we can "throw the switch" in exactly one place if we want to switch protocols.
@@ -11,49 +15,46 @@
*/
public class AsyncProtoFactory {
//this is the magic switch
- private static final boolean USE_SIMPLE_SOCKET=true;
+ private static final boolean USE_SIMPLE_SOCKET=false;
/**
* Get a handler for this protocol. This is the client side call. This fails if the connection
* cannot be made. It returns a connected proto object.
*
- * @param host
- * @param selector a proto-specific object
+ * @param host pass in a service descriptor (tells us how to find the server)
+ * @param boolean wantProxy true if you want the proxy server, false if you want the real sim server
* @return
* @throws IOException
*/
- public static AsyncProto getDefaultClient(String host, Object selector) throws IOException {
+ public static AsyncProto getDefaultClient(WebAPIDescriptor descriptor, boolean wantProxy) throws IOException {
if (USE_SIMPLE_SOCKET) {
- return simpleSocketProto(host, selector);
+ if (wantProxy) {
+ return simpleSocketProto(descriptor.getServiceStateURI().getHost(),SimpleSocketAsync.DEFAULT_PROXY_PORT);
+ } else {
+ return simpleSocketProto(descriptor.getServiceStateURI().getHost(),SimpleSocketAsync.DEFAULT_SIM_PORT);
+ }
} else {
- return cometProto(host,(String)selector);
+ if (wantProxy) {
+ return cometProto(descriptor.getCometProxyURI());
+ } else {
+ return cometProto(descriptor.getCometSimURI());
+ }
}
}
- private static AsyncProto cometProto(String host, String selector) throws IOException {
- return new CometClient(host,selector).getProto();
+ private static AsyncProto cometProto(URI cometURI) throws IOException {
+ //return new CometClient(host,selector).getProto();
+ return CometClient.getProto(cometURI);
}
- private static AsyncProto simpleSocketProto(String host, Object selector) throws IOException {
- if (USE_SIMPLE_SOCKET) {
- return simpleSocketInfo(host, selector);
- } else {
- return cometProto(host,(String)selector);
- }
+ private static AsyncProto simpleSocketProto(String host, int port) throws IOException {
+ return new SimpleSocketAsync(new Socket(host,port));
}
- private static AsyncProtoInfo cometInfo() {
- return new CometInfo();
- }
-
- private static AsyncProto simpleSocketInfo(String host, Object selector) throws IOException {
- return new SimpleSocketAsync(host, ((Integer)selector).intValue());
- }
-
- public static AsyncProtoInfo getDefaultInfo() {
+ public static String getScheme() {
if (USE_SIMPLE_SOCKET) {
- return new SimpleSocketInfo();
+ return "og";
} else {
- return new CometInfo();
+ return "comet";
}
}
}
Deleted: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProtoInfo.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProtoInfo.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/AsyncProtoInfo.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -1,15 +0,0 @@
-package com.ogoglio.message.proto;
-
-
-/**
- * The intention of this interface is to hide various specifics about how the underlying async
- * protocol is implemented. The objects returned here should be considered opaque.
- *
- * @author iansmith
- *
- */
-public interface AsyncProtoInfo {
- public String getScheme();
- public Object getProxySpecificSelector();
- public Object getSimSpecificSelector();
-}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometClient.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometClient.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometClient.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -1,119 +1,141 @@
package com.ogoglio.message.proto;
-import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
import java.io.Writer;
-import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.URI;
-import com.ogoglio.message.MessageHandler;
-import com.ogoglio.message.TCPChannel.Listener;
+import com.ogoglio.message.Command;
+import com.ogoglio.util.Log;
public class CometClient {
- //comet works over HTTP
- private HttpURLConnection connection;
+ public static final int BAD_CMD = -210;
+ public static final int CMD_BUFFERED = -230;
+
+ private static final String EXPECTED_OK="HTTP/1.1 200";
- //most people just want to read/write to it
- public OutputStream os;
- public InputStream is;
+ public static final String CRLF="\r\n";
+ public static final String EOC = "0"+CRLF+CRLF; //end of chunk
- private static final String CRLF="\r\n";
- private static final String EOC = "0"+CRLF+CRLF; //end of chunk
+ public static final int COMET_BUFF_SIZE=512;
- public static final int XXX_PORT=8080;
- public static final String XXX_MOUNT_POINT="/og/comet";
+ //public static final int XXX_PORT=8080;
+ //public static final String XXX_MOUNT_POINT="/og/comet";
+ //public static final String XXX_HOST="localhost";
- private Locator remote;
- private Locator local;
-
- public CometClient(String remoteHost, String selector) throws IOException {
- Socket socket=new Socket(remoteHost,XXX_PORT); ///UGH
- is = socket.getInputStream();
- os = socket.getOutputStream();
+ public static CometProto getProto(URI uri) throws IOException {
+ Socket socket = new Socket();
+ int port=80;
+ if (uri.getPort()>0) {
+ port=uri.getPort();
+ }
+ SocketAddress address = new InetSocketAddress(uri.getHost(),port);
+ socket.connect(address,15000);
- StringBuffer buff=new StringBuffer();
- buff.append("POST "+XXX_MOUNT_POINT+selector+" HTTP/1.1"+CRLF);
- buff.append("content-type: text/plain"+CRLF);
- buff.append("host: "+remoteHost+":"+XXX_PORT+CRLF);
- buff.append("connection: keep-alive"+CRLF);
- buff.append("user-agent: ogoglio/viewer"+CRLF);
- //if you omit this, the server generates the "end" immediately
- buff.append("content-length: 17"+CRLF);
- //buff.append("accept= text/plain"+CRLF);
- buff.append("method: POST"+CRLF);
- //buff.append("transfer-encoding= chunked"+CRLF);
- buff.append(CRLF);
- os.write(buff.toString().getBytes());
- os.flush();
-
- String scheme = new CometInfo().getScheme();
- remote = new Locator(scheme+"://"+remoteHost+":"+XXX_PORT+XXX_MOUNT_POINT+selector);
+ InputStream is=socket.getInputStream();
+ OutputStream os=socket.getOutputStream();
+ Writer writer=new OutputStreamWriter(os);
+
+ sendHTTPStartupInfo(writer, uri.getHost(), uri.getPath());
+ String response=getHTTPResponse(is);
+ if (!response.startsWith(EXPECTED_OK)) {
+ throw new IOException("Problem connecting to server. HTTP Response:"+response);
+ }
+ if (!response.endsWith("\r\n\r\n")) {
+ throw new IOException("Problem connecting to server, no empty line! HTTP Response:"+response);
+ }
+ String scheme=AsyncProtoFactory.getScheme(),localStr,remoteStr;
InetSocketAddress addr=(InetSocketAddress)socket.getLocalSocketAddress();
- local = new Locator(scheme+"://UNKNOWN@"+addr.getHostName()+":"+addr.getPort()+"/");
+
+ localStr = scheme+"://UNKNOWN@"+addr.getHostName()+":"+addr.getPort()+"/";
+ remoteStr = scheme+"://"+uri.getHost()+":"+uri.getPort()+uri.getPath();
+
+ Locator remote=new Locator(remoteStr);
+ Locator local=new Locator(localStr);
+ return new CometProto(writer,is,remote,local,true);
}
+
+ private static void sendHTTPStartupInfo(Writer wr, String host, String path) throws IOException {
+ sendLine("POST "+path+" HTTP/1.1", wr);
+ sendLine("Host: "+host, wr);
+ sendLine("Transfer-encoding: chunked",wr);
+ sendLine("",wr);
+ wr.flush();
+ }
+
+ private static String getHTTPResponse(InputStream is) throws IOException {
+ byte[] buffer=new byte[1024];
+ int n=is.read(buffer);
+ if (n>0) {
+ String s=new String(buffer,0,n);
+ return s;
+ }
+ throw new IOException("getHTTPResponse at setup failed ("+n+")");
+ }
- public CometProto getProto() {
- return new CometProto(new PrintWriter(os), is, remote, local);
+ private static void sendLine(String string, Writer wr) throws IOException {
+ String withCR=string+CRLF;
+ wr.write(withCR);
}
- public CometClient(String remoteHost, int remotePort, MessageHandler messageHandler, boolean ensureOrigin, Listener listener) throws IOException {
- Socket socket=new Socket(remoteHost,remotePort);
- is = socket.getInputStream();
- os = socket.getOutputStream();
-
- StringBuffer buff=new StringBuffer();
- buff.append("POST /og/comet/fart/poop HTTP/1.1"+CRLF);
- buff.append("content-type: text/plain"+CRLF);
- buff.append("host: "+remoteHost+":"+remotePort+CRLF);
- buff.append("connection: keep-alive"+CRLF);
- buff.append("user-agent: ogoglio/viewer"+CRLF);
- //if you omit this, the server generates the "end" immediately
- buff.append("content-length: 17"+CRLF);
- //buff.append("accept= text/plain"+CRLF);
- buff.append("method: POST"+CRLF);
- //buff.append("transfer-encoding= chunked"+CRLF);
- buff.append(CRLF);
- os.write(buff.toString().getBytes());
- os.flush();
-
+ public static void sendLineChunked(String string, Writer wr) throws IOException {
+ sendLine(Integer.toHexString(string.length()),wr);
+ sendLine(string,wr);
+ wr.flush();
}
-
-
- public static void main(String[] argv) {
+
+ public static String pullOutNextMessage(StringBuffer buff) {
+ //if you have no "$" then you are right at the front
+ if (buff.indexOf("$")==-1) {
+ Log.info("Unusual buffer situation, no $ found yet out of "+buff.length()+" chars...");
+ return null;
+ }
+ int result = CometClient.pullOutCommandPart(buff);
+ if (result== CometClient.BAD_CMD) {
+ return null;
+ }
+ if (result== CometClient.CMD_BUFFERED) {
+ //Log.info("Buffered partial packet of "+buff.length()+" chars...");
+ return null;
+ }
+ //the result is the size of the substring we want
+ String msg=buff.substring(0,result);
+ buff.delete(0, result);
+ return msg;
+ }
+
+ public static int pullOutCommandPart(StringBuffer buff) {
+ String command=buff.substring(0,buff.indexOf("$"));
+ String msg=buff.substring(buff.indexOf("$")+1);
+ String lenPart=command.substring(Command.MESSAGE.length()+1);
+ int len=-1;
try {
- CometClient client=new CometClient("localhost",8080,null,false,null);
- OutputStreamWriter wr=new OutputStreamWriter(client.os);
- PrintWriter pr=new PrintWriter(wr);
- StringBuffer data=new StringBuffer();
- data.append(argv[0]+":"+argv[1]+"\n");
-
- pr.print(data.toString());
- pr.flush();
-
-
- InputStreamReader isr=new InputStreamReader(client.is);
- BufferedReader rd=new BufferedReader(isr);
- String line=null;
- do {
- line=rd.readLine();
- if (line!=null) {
- System.out.println("<--:"+line);
+ len=Integer.parseInt(lenPart);
+ if (len<=msg.length()) {
+ int dollarIndex=buff.indexOf("$");
+ //we actually don't want it if the $ is the last one because then we have no msg
+ if (dollarIndex+1==buff.length()) {
+ return CMD_BUFFERED;
}
- } while (rd!=null);
-
- } catch (IOException e) {
- System.out.println("WHOA! IO EXCEPTION");
- e.printStackTrace();
+ //we have a whole msg of length len... so strip out command part
+ buff.delete(0, dollarIndex+1);
+ return len;
+ }
+ return CMD_BUFFERED;
+ } catch (NumberFormatException e) {
+ Log.error("Command isn't well formed!"+buff+"["+lenPart+"]...destroying buffer!");
+ buff.delete(0, buff.length());
+ return BAD_CMD;
}
+
}
+}
-}
Deleted: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometInfo.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometInfo.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometInfo.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -1,21 +0,0 @@
-package com.ogoglio.message.proto;
-
-
-public class CometInfo implements AsyncProtoInfo {
-
- public CometInfo() {
- }
-
- public Object getProxySpecificSelector() {
- return "/proxy";
- }
-
- public String getScheme() {
- return "comet";
- }
-
- public Object getSimSpecificSelector() {
- return "/sim";
- }
-
-}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometProto.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometProto.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometProto.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -8,19 +8,19 @@
public class CometProto implements AsyncProto {
private Writer writer;
- private InputStream input;
+ private LineOrientedCRLFSocket input;
private Locator local;
private Locator remote;
-
- private StringBuffer waiting=new StringBuffer();
+ private boolean needsChunking;
+ StringBuffer buffer=new StringBuffer();
- public CometProto(Writer writer, InputStream input, Locator remote, Locator local) {
+ public CometProto(Writer writer, InputStream input, Locator remote, Locator local, boolean needsChunking) {
this.writer=writer;
- this.input=input;
+ this.input=new LineOrientedCRLFSocket(input);
this.local=local;
this.remote=remote;
+ this.needsChunking=needsChunking;
}
-
public Locator getLocalLocator() {
return local;
}
@@ -38,51 +38,67 @@
}
public String readLine() throws IOException {
- byte[] buf = new byte[512];
- waiting.delete(0, waiting.length());
- do {
- int n = input.read(buf); //can throw an IOException
- if (n > 0) {
- waiting.append(new String(buf, 0, n));
- } else if (n < 0) {
- Log.error("Unable to read from stream! Error: read returned < 0:"+n);
- throw new IOException("Can't read from stream [<0 in read()]");
- }
- } while (input.available() >0);
+ if (input==null) {
+ throw new IOException("Can't read on a stream that is already closed [readLine].");
+ }
+ String chunkLine=input.waitForNextLine();
+ String dataLine=input.waitForNextLine();
- if (waiting.indexOf("\n")!=waiting.length()) {
- Log.error("Did not get a single string terminated by a newline!");
+ if (chunkLine.equals("0")) {
+ throw new NegativeReadValueException("Read EOC from server! Closing!");
}
- return waiting.toString();
- }
-
- public String readString(int length) throws IOException {
- byte[] buf = new byte[512];
- waiting.delete(0, waiting.length());
- do {
- int n = input.read(buf); //can throw an IOException
- if (n > 0) {
- waiting.append(new String(buf,0,n));
- } else if (n < 0) {
- Log.error("Unable to read from stream! Error: read returned < 0:"+n);
- throw new IOException("Can't read from stream [<0 in read()]");
+
+ try {
+ int len=Integer.parseInt(chunkLine,16);
+ if (len!=dataLine.length()) {
+ Log.error("Whoa! Chunk wasn't the size we expected:"+chunkLine+"->"+dataLine);
}
- } while (waiting.length()<length);
- return waiting.toString();
+ } catch (NumberFormatException e) {
+ Log.error("Whoa! Chunk line wasn't well formed:"+chunkLine);
+ }
+
+ buffer.append(dataLine);
+ return CometClient.pullOutNextMessage(buffer);
}
+/* public String readString(int length) throws IOException {
+ throw new IOException("Not implemented for this protocol");
+ if (input==null) {
+ throw new IOException("Can't read on a stream that is already closed [readString].");
+ }
+ String next=input.waitForNextLine();
+ if (next.length()!=length) {
+ throw new IOException("We are out of sync with the protocol!");
+ }
+ return next;
+
+ }*/
+
public void sendMessage(String command, String message) throws IOException {
- writer.write(command + "\n");
- writer.write(message);
+ String bunch=command+"$"+message;
+ if (writer==null) {
+ throw new IOException("Can't write on a stream that is already closed [sendMessage].");
+ }
+ if (needsChunking) {
+ CometClient.sendLineChunked(bunch, writer);
+ } else {
+ //this is evil breaking of modularity! b/c we know that tomcat doesn't synchronize
+ //access to the writer, we do it here, way down the stack and without real justification or API
+ synchronized (writer) {
+ writer.write(bunch);
+ writer.flush();
+ }
+ }
}
-
+
public void shutdown() {
- try {
- input.close();
- writer.close();
- } catch (IOException e) {
- Log.error("Error closing input/output streams of comet!",e);
- }
+ //this isn't really what we'd like to do, but we would need a bunch of machinery to know
+ //if it was safe to call "close" b/c that would break the comet servlet which reuses
+ //these objects... the client side probably *should* call close.
+
+ //how should we synchronize this?
+ input=null;
+ writer=null;
}
}
Added: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/LineOrientedCRLFSocket.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/LineOrientedCRLFSocket.java (rev 0)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/LineOrientedCRLFSocket.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -0,0 +1,46 @@
+package com.ogoglio.message.proto;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import com.ogoglio.util.Log;
+
+public class LineOrientedCRLFSocket {
+
+ private InputStream is;
+ private StringBuffer buffer=new StringBuffer();
+
+ public LineOrientedCRLFSocket(InputStream is) {
+ this.is=is;
+ }
+
+ public String waitForNextLine() throws IOException {
+ int index;
+ while ((index=buffer.indexOf(CometClient.CRLF))==-1) {
+ //no full line in buffer
+ fill();
+ }
+ String front=buffer.substring(0, index); //drop the \r\n terminator
+ buffer.delete(0, index+2);
+
+ return front;
+ }
+
+ public void fill() throws IOException {
+ byte buf[]=new byte[CometClient.COMET_BUFF_SIZE];
+ int n = is.read(buf);
+ if (n<0) {
+ is.close();
+ is=null;
+ throw new NegativeReadValueException("Negative value reading from socket! [n="+n+"]");
+ }
+ buffer.append(new String(buf,0,n));
+ //Log.info("LineOriented [client] read "+n+" bytes:"+buffer);
+ }
+
+ public void close() throws IOException {
+ if (is!=null) {
+ is.close();
+ }
+ }
+}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/Locator.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/Locator.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/Locator.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -14,14 +14,14 @@
package com.ogoglio.message.proto;
+import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.UnknownHostException;
public class Locator {
- public static final AsyncProtoInfo info = AsyncProtoFactory.getDefaultInfo();
-
private URI uri = null;
public Locator(String locatorString) {
@@ -30,41 +30,35 @@
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Bad locatorString: " + locatorString);
}
- if (uri.getPort() <= 0) {
+ int port = 80;
+ if (uri.getPort() < -1) { //-1 is legal and implies 80
throw new IllegalArgumentException("bad port: " + uri.getPort());
+ } else if (uri.getPort() > 0){
+ port = uri.getPort();
}
- if (!info.getScheme().equals(uri.getScheme())) {
+ if (!AsyncProtoFactory.getScheme().equals(uri.getScheme())) {
throw new IllegalArgumentException("bad scheme: " + uri.getScheme());
}
- }
-
- public String getHost() {
- return uri.getHost();
- }
-
- /*
- public void setPort(int port) {
- String newURI = uri.getScheme() + "://" + uri.getHost() + ":" + port + "/";
+ /*
+ * These have to be normalized to IP addresses if they are going to be useful.
+ */
try {
- uri = new URI(newURI);
+ String hostAsName=uri.getHost();
+ InetAddress addr=InetAddress.getByName(hostAsName);
+ String hostAsNumber=addr.getHostAddress();
+ uri = new URI(uri.getScheme(),uri.getUserInfo(),hostAsNumber,port,uri.getPath(),uri.getQuery(),uri.getFragment());
+ } catch (UnknownHostException ex) {
+ throw new IllegalArgumentException("Hostname supplied in locator is bogus:"+uri.getHost());
} catch (URISyntaxException e) {
- throw new IllegalStateException("Bad uri: " + newURI);
+ throw new IllegalArgumentException("Bad locatorString when we tried to normalize! " + locatorString);
}
+
}
- public void setHost(String host) {
- if (host == null || host.trim().length() == 0) {
- throw new IllegalArgumentException("Bad host name: " + host);
- }
- String newURI = uri.getScheme() + "://" + host + ":" + uri.getPort() + "/";
- try {
- uri = new URI(newURI);
- } catch (URISyntaxException e) {
- throw new IllegalStateException("Bad uri: " + newURI);
- }
-
+ public String getHost() {
+ return uri.getHost();
}
- */
+
public int getPort() {
return uri.getPort();
}
Added: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/NegativeReadValueException.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/NegativeReadValueException.java (rev 0)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/NegativeReadValueException.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -0,0 +1,10 @@
+package com.ogoglio.message.proto;
+
+import java.io.IOException;
+
+
+public class NegativeReadValueException extends IOException {
+ public NegativeReadValueException(String msg) {
+ super(msg);
+ }
+}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/SimpleSocketAsync.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/SimpleSocketAsync.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/SimpleSocketAsync.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -18,6 +18,10 @@
*/
public class SimpleSocketAsync implements AsyncProto {
+ public static final int DEFAULT_PROXY_PORT = 49355;
+
+ public static final int DEFAULT_SIM_PORT = 8922;
+
public static int MAX_COMMAND_LENGTH = 2048; //TODO decide whether 2048 bytes is enough for a max command length
public static int MAX_MESSAGE_LENGTH = 2048; //TODO decide whether 2048 bytes is enough for a max message length
@@ -31,10 +35,6 @@
private StringBuffer commandBuffer = new StringBuffer();
private StringBuffer messageBuffer = new StringBuffer();
-
- public SimpleSocketAsync(String host, int port) throws IOException {
- this(new Socket(host, port));
- }
public SimpleSocketAsync(Socket socket) {
this.socket=socket;
@@ -51,7 +51,7 @@
}
private Locator sockAddrToScheme(InetSocketAddress addr) {
- String scheme = AsyncProtoFactory.getDefaultInfo().getScheme();
+ String scheme = AsyncProtoFactory.getScheme();
return new Locator(scheme +"://"+addr.getHostName()+":"+addr.getPort());
}
@@ -99,7 +99,7 @@
commandBuffer.delete(0, commandBuffer.length());
return result;
}
-
+/*
public String readString(int length) throws IOException {
int ct = 0;
while (ct < length) {
@@ -118,7 +118,7 @@
messageBuffer.delete(0, messageBuffer.length());
return result;
}
-
+*/
public void prepareOutput() throws IOException {
if (socketOutput == null) {
socketOutput = socket.getOutputStream();
Deleted: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/SimpleSocketInfo.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/SimpleSocketInfo.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/SimpleSocketInfo.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -1,26 +0,0 @@
-package com.ogoglio.message.proto;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-
-public class SimpleSocketInfo implements AsyncProtoInfo {
-
- private static final int DEFAULT_SIM_PORT=8932;
- private static final int DEFAULT_PROXY_PORT=43092;
-
- private static final String SCHEME = "og";
-
- public Object getProxySpecificSelector() {
- return new Integer(DEFAULT_PROXY_PORT);
- }
-
- public String getScheme() {
- return SCHEME;
- }
-
- public Object getSimSpecificSelector() {
- return new Integer(DEFAULT_SIM_PORT);
- }
-
-}
Modified: maven/trunk/ogoglio-integration-test/pom.xml
===================================================================
--- maven/trunk/ogoglio-integration-test/pom.xml 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-integration-test/pom.xml 2007-11-09 00:10:49 UTC (rev 566)
@@ -13,7 +13,7 @@
<relativePath>../ogoglio</relativePath>
</parent>
<artifactId>ogoglio-integration-test</artifactId>
- <packaging>pom</packaging>
+ <packaging>jar</packaging>
<build>
<testResources>
@@ -62,35 +62,6 @@
<skip>true</skip><!--skip unit tests -->
</configuration>
</plugin>
- <!--need to compile b/c POM packaging doesn't get it by def -->
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <executions>
- <execution>
- <id>build integration tests</id>
- <phase>test-compile</phase>
- <goals>
- <goal>testCompile</goal>
- </goals>
- </execution>
- </executions>
- <configuration />
- </plugin>
- <!--need to do resources b/c POM packaging doesn't get them by def -->
- <plugin>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>build integration tests</id>
- <phase>process-test-resources</phase>
- <goals>
- <goal>testResources</goal>
- </goals>
- </execution>
- </executions>
- <configuration />
- </plugin>
-
</plugins>
</build>
Added: maven/trunk/ogoglio-integration-test/src/main/java/com/ogoglio/amazon/test/CometTest.java
===================================================================
--- maven/trunk/ogoglio-integration-test/src/main/java/com/ogoglio/amazon/test/CometTest.java (rev 0)
+++ maven/trunk/ogoglio-integration-test/src/main/java/com/ogoglio/amazon/test/CometTest.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -0,0 +1,104 @@
+package com.ogoglio.amazon.test;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Vector;
+
+import com.ogoglio.client.SpaceClient;
+import com.ogoglio.client.WebAPIAuthenticator;
+import com.ogoglio.client.WebAPIClient;
+import com.ogoglio.client.WebAPIClientWire;
+import com.ogoglio.client.WebAPIDescriptor;
+import com.ogoglio.client.model.Thing;
+import com.ogoglio.xml.SpaceDocument;
+
+public class CometTest implements SpaceClient.Listener{
+
+ private String host;
+ private String user;
+ private String password;
+
+ public CometTest(String host, String user, String password) {
+ this.host=host;
+ this.user=user;
+ this.password=password;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ if (args.length!=3) {
+ usage();
+ }
+ try {
+ CometTest test=new CometTest(args[0],args[1],args[2]);
+ test.start();
+ } catch (URISyntaxException e) {
+ System.err.println("Couldn't form a URI from the given host:"+e.getMessage());
+ } catch (IOException e) {
+ System.err.println("IOException :"+e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void usage() {
+ System.err.println("usage: AmazonCometTest ec2-67-202-23-0.compute-1.amazonaws.com user password");
+ System.exit(1);
+ }
+
+ private void start() throws URISyntaxException, IOException {
+ WebAPIDescriptor descriptor = new WebAPIDescriptor(new URI("http://"+host+":80/og/"));
+ WebAPIClientWire wire=new WebAPIClientWire();
+ WebAPIAuthenticator auth = new WebAPIAuthenticator(wire,descriptor,user,password);
+ WebAPIClient webclient = new WebAPIClient(descriptor,auth,wire);
+
+ SpaceDocument space=webclient.createSpace("testing remote access");
+ long spaceID=space.getSpaceID();
+ System.out.println("Last changed ["+space.getDisplayName()+"]:"+space.getLastModifiedAsUTC());
+ //make a space for us to play in
+ webclient.setSpacePublished(spaceID, true);
+
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ }
+
+ SpaceClient client=new SpaceClient(spaceID,descriptor.getServiceURI(),auth.getAuthCookie(),this);
+ System.out.println("Got a connected client!");
+ webclient.deleteSpace(spaceID);
+ }
+
+ public void contextItemChosen(Thing thing, long nonce, String id) {
+ }
+
+ public void disconnected() {
+ System.out.println("Disconnected from space");
+ }
+
+ public void receivedBrowserMessage(long sourceThingID, String message) {
+ }
+
+ public void receivedChatMessage(String username, String message) {
+ }
+
+ public void receivedCommandFocusRequest() {
+ }
+
+ public void receivedContextMenuData(long nonce, String errorIfAny, Vector contextMenu) {
+ }
+
+ public void receivedContextMenuRequest(Thing thing, String shapeName, int x, int y, long nonce) {
+ }
+
+ public void receivedInfoPanel(long sourceThingID, String nonce) {
+ }
+
+ public void receivedLink(String displayName, String link) {
+ }
+
+ public void receivedSpaceTransfer(URI link) {
+ }
+
+}
Added: maven/trunk/ogoglio-integration-test/src/main/scripts/testComet
===================================================================
--- maven/trunk/ogoglio-integration-test/src/main/scripts/testComet (rev 0)
+++ maven/trunk/ogoglio-integration-test/src/main/scripts/testComet 2007-11-09 00:10:49 UTC (rev 566)
@@ -0,0 +1,2 @@
+#!/bin/bash
+java -cp ../../../target/classes\:$HOME/.m2/repository/com/ogoglio/ogoglio-common/0.0.1-SNAPSHOT/ogoglio-common-0.0.1-SNAPSHOT.jar com.ogoglio.amazon.test.CometTest $1 $2 $3
Property changes on: maven/trunk/ogoglio-integration-test/src/main/scripts/testComet
___________________________________________________________________
Name: svn:executable
+ *
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/AsyncClientReady.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/AsyncClientReady.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/AsyncClientReady.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -1,5 +1,6 @@
package com.ogoglio.message.server;
+import com.ogoglio.message.TCPChannel;
import com.ogoglio.message.proto.AsyncProto;
/**
@@ -14,5 +15,5 @@
*/
public interface AsyncClientReady {
- public void clientReady(AsyncProto newlyConnectedProto);
+ public TCPChannel clientReady(AsyncProto newlyConnectedProto);
}
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/AsyncProtoServerFactory.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/AsyncProtoServerFactory.java 2007-11-08 00:25:45 UTC (rev 565)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/message/server/AsyncProtoServerFactory.java 2007-11-09 00:10:49 UTC (rev 566)
@@ -1,20 +1,15 @@
package com.ogoglio.message.server;
import java.io.IOException;
+import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import com.ogoglio.message.MessageHandler;
-import com.ogoglio.message.proto.AsyncProtoInfo;
-import com.ogoglio.message.proto.CometInfo;
-import com.ogoglio.message.proto.SimpleSocketInfo;
-import com.ogoglio.util.Log;
-
public class AsyncProtoServerFactory {
//this is the magic switch
- private static final boolean USE_SIMPLE_SOCKET=true;
+ private static final boolean USE_SIMPLE_SOCKET=false;
private static Map selectorToChannelManager = Collections.synchronizedMap(new HashMap());
/**
@@ -28,57 +23,27 @@
*/
public static AsyncProtoShutdownHandle waitForClient(Object serverSelector, AsyncClientReady ready) throws IOException {
if (USE_SIMPLE_SOCKET) {
- return simpleSocketImpl(((Integer)serverSelector).intValue(),ready);
+ throw new IllegalArgumentException("Currently unavailable protocol!");
+ //return simpleSocketImpl(((Integer)serverSelector).intValue(),ready);
} else {
return cometImpl(serverSelector, ready);
}
}
- public static AsyncProtoInfo getInfo() {
- if (USE_SIMPLE_SOCKET) {
- return simpleSocketInfo();
- } else {
- return cometInfo();
- }
- }
-
- private static AsyncProtoInfo simpleSocketInfo() {
- return new SimpleSocketInfo();
- }
-
private static AsyncProtoShutdownHandle simpleSocketImpl(int port, AsyncClientReady ready) throws IOException {
SimpleSocketWaiterThread waiter = new SimpleSocketWaiterThread(port,ready);
waiter.start();
return waiter.getShutdownHandle();
}
- private static AsyncProtoInfo cometInfo() {
- return new CometInfo();
- }
-
private static AsyncProtoShutdownHandle cometImpl(Object serverSelector, AsyncClientReady ready) {
- String urlPart = (String)serverSelector;
- CometChannelManager mgr = new CometChannelManager(urlPart,ready);
+ URI uri= (URI)serverSelector;
+ CometChannelManager mgr = new CometChannelManager(uri,ready);
selectorToChannelManager.put(serverSelector, mgr);
return mgr;
}
public static boolean needsReaderThreadsOnServerSide() {
return USE_SIMPLE_SOCKET;
- }
-
- public static void registerMessageHandler(Object serverSelector, MessageHandler messageHandler) {
- if (USE_SIMPLE_SOCKET) {
- Log.error("S...
[truncated message content] |