|
From: <tre...@us...> - 2007-11-19 20:44:45
|
Revision: 592
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=592&view=rev
Author: trevorolio
Date: 2007-11-19 12:44:43 -0800 (Mon, 19 Nov 2007)
Log Message:
-----------
A couple of tweaks:
Caused Log to init at class initialization instead of first log (which had concurrency errors).
CometProto no longer throws null pointer exceptions during shutdown if the wrapper is already null (not thread safe, though).
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometProto.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/Log.java
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-19 19:44:11 UTC (rev 591)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometProto.java 2007-11-19 20:44:43 UTC (rev 592)
@@ -8,19 +8,25 @@
public class CometProto implements AsyncProto {
private Writer writer;
+
private LineOrientedCRLFSocket input;
+
private Locator local;
+
private Locator remote;
+
private boolean needsChunking;
- StringBuffer buffer=new StringBuffer();
-
+
+ StringBuffer buffer = new StringBuffer();
+
public CometProto(Writer writer, InputStream input, Locator remote, Locator local, boolean needsChunking) {
- this.writer=writer;
- this.input=new LineOrientedCRLFSocket(input);
- this.local=local;
- this.remote=remote;
- this.needsChunking=needsChunking;
+ this.writer = writer;
+ this.input = new LineOrientedCRLFSocket(input);
+ this.local = local;
+ this.remote = remote;
+ this.needsChunking = needsChunking;
}
+
public Locator getLocalLocator() {
return local;
}
@@ -34,49 +40,49 @@
}
public void prepareOutput() throws IOException {
- //no effect in comment
+ //no effect in comment
}
public String readLine() throws IOException {
- if (input==null) {
+ 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();
-
+ String chunkLine = input.waitForNextLine();
+ String dataLine = input.waitForNextLine();
+
if (chunkLine.equals("0")) {
throw new NegativeReadValueException("Read EOC from server! Closing!");
}
-
+
try {
- int len=Integer.parseInt(chunkLine,16);
- if (len!=dataLine.length()) {
- Log.error("Whoa! Chunk wasn't the size we expected:"+chunkLine+"->"+dataLine);
+ int len = Integer.parseInt(chunkLine, 16);
+ if (len != dataLine.length()) {
+ Log.error("Whoa! Chunk wasn't the size we expected:" + chunkLine + "->" + dataLine);
}
} catch (NumberFormatException e) {
- Log.error("Whoa! Chunk line wasn't well formed:"+chunkLine);
+ 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 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 {
- String bunch=command+"$"+message;
- if (writer==null) {
+ String bunch = command + "$" + message;
+ if (writer == null) {
throw new IOException("Can't write on a stream that is already closed [sendMessage].");
}
if (needsChunking) {
@@ -90,28 +96,28 @@
}
}
}
-
+
public void shutdown() {
Log.info("Shutting down Comet Proto, flushing...");
- if (writer!=null) {
+ if (writer != null) {
try {
writer.flush();
} catch (IOException e) {
- Log.error("Problem attempting to flush comet proto buffers:"+e.getMessage());
+ Log.error("Problem attempting to flush comet proto buffers:" + e.getMessage());
}
- }
- //again, a horrible modularity break: we *know* that needs chunking implies we are on the
- //client side
- if (needsChunking) {
- try {
- Log.info("Closing client-side connection to server since we are shutting down.");
- writer.close();
- } catch (IOException e) {
- Log.error("Unable to close connection to server:"+e.getMessage());
+ //again, a horrible modularity break: we *know* that needs chunking implies we are on the
+ //client side
+ if (needsChunking) {
+ try {
+ Log.info("Closing client-side connection to server since we are shutting down.");
+ writer.close();
+ } catch (IOException e) {
+ Log.error("Unable to close connection to server:" + e.getMessage());
+ }
}
}
- input=null;
- writer=null;
+ input = null;
+ writer = null;
}
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/Log.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/Log.java 2007-11-19 19:44:11 UTC (rev 591)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/Log.java 2007-11-19 20:44:43 UTC (rev 592)
@@ -66,6 +66,11 @@
SpaceEvent.THING_START_MOTION_EVENT,
SpaceEvent.SHAPE_START_MOTION_EVENT
};
+
+ static {
+ faultInLogger();
+ }
+
public static void faultInLogger() {
try {
if (faultedInAlready) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|