Skip to content

Commit

Permalink
Remove string bindings in the java reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Aug 4, 2009
1 parent c66075e commit 114ba43
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 85 deletions.
34 changes: 16 additions & 18 deletions java/src/com/rubyeventmachine/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,23 @@ public class Application {
public class Reactor extends EmReactor {

private Application application;
private TreeMap<String, Timer> timers;
private TreeMap<String, Connection> connections;
private TreeMap<String, ConnectionFactory> acceptors;
private TreeMap<Long, Timer> timers;
private TreeMap<Long, Connection> connections;
private TreeMap<Long, ConnectionFactory> acceptors;
/**
*
*/
public Reactor (Application app) {
application = app;
timers = new TreeMap<String, Timer>();
connections = new TreeMap<String, Connection>();
acceptors = new TreeMap<String, ConnectionFactory>();
timers = new TreeMap<Long, Timer>();
connections = new TreeMap<Long, Connection>();
acceptors = new TreeMap<Long, ConnectionFactory>();
}


public void eventCallback (String sig, int eventType, ByteBuffer data) {
public void eventCallback (long sig, int eventType, ByteBuffer data, long data2) {
if (eventType == EM_TIMER_FIRED) {
String timersig = new String (data.array());
//System.out.println ("EVSIG "+sig + "..."+new String(data.array()));
Timer r = timers.remove(timersig);
Timer r = timers.remove(data2);
if (r != null)
r._fire();
else
Expand All @@ -93,7 +91,7 @@ else if (eventType == EM_CONNECTION_ACCEPTED) {
ConnectionFactory f = acceptors.get(sig);
if (f != null) {
Connection c = f.connection();
c.signature = new String (data.array());
c.signature = data2;
c.application = application;
connections.put(c.signature, c);
c.postInit();
Expand Down Expand Up @@ -124,14 +122,14 @@ public Application() {
public void addTimer (double seconds, Timer t) {
t.application = this;
t.interval = seconds;
String s = reactor.installOneshotTimer ((int)(seconds * 1000));
long s = reactor.installOneshotTimer ((int)(seconds * 1000));
reactor.timers.put(s, t);

}

public void bindConnect (String bindAddr, int bindPort, String host, int port, Connection c) {
try {
String s = reactor.connectTcpServer(bindAddr, bindPort, host, port);
long s = reactor.connectTcpServer(bindAddr, bindPort, host, port);
c.application = this;
c.signature = s;
reactor.connections.put(s, c);
Expand All @@ -144,7 +142,7 @@ public void connect (String host, int port, Connection c) {
}

public void startServer (SocketAddress sa, ConnectionFactory f) throws EmReactorException {
String s = reactor.startTcpServer(sa);
long s = reactor.startTcpServer(sa);
reactor.acceptors.put(s, f);
}

Expand All @@ -165,17 +163,17 @@ public void fire() {
run();
}

public void sendData (String sig, ByteBuffer bb) {
public void sendData (long sig, ByteBuffer bb) {
try {
reactor.sendData(sig, bb);
} catch (IOException e) {}
}

public void sendDatagram (String sig, ByteBuffer bb, InetSocketAddress target) {
public void sendDatagram (long sig, ByteBuffer bb, InetSocketAddress target) {
reactor.sendDatagram(sig, bb, target.getHostName(), target.getPort());
}

public void closeConnection (String sig, boolean afterWriting) {
public void closeConnection (long sig, boolean afterWriting) {
try {
reactor.closeConnection(sig, afterWriting);
} catch (ClosedChannelException e) {}
Expand All @@ -186,7 +184,7 @@ public void openDatagramSocket (Connection c) {
}
public void openDatagramSocket (InetSocketAddress addr, Connection c) {
try {
String s = reactor.openUdpSocket(addr);
long s = reactor.openUdpSocket(addr);
c.application = this;
c.signature = s;
reactor.connections.put(s, c);
Expand Down
2 changes: 1 addition & 1 deletion java/src/com/rubyeventmachine/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class Connection {

public Application application;
public String signature;
public long signature;

public void postInit() {}
public void connectionCompleted() {}
Expand Down
Loading

0 comments on commit 114ba43

Please sign in to comment.