|
|
@ -35,6 +35,8 @@ package com.jme3.network.base; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
|
|
|
|
|
|
import com.jme3.network.Message; |
|
|
|
import com.jme3.network.Message; |
|
|
|
import com.jme3.network.MessageListener; |
|
|
|
import com.jme3.network.MessageListener; |
|
|
@ -64,6 +66,9 @@ public class ConnectorAdapter extends Thread |
|
|
|
private MessageListener<Object> dispatcher; |
|
|
|
private MessageListener<Object> dispatcher; |
|
|
|
private AtomicBoolean go = new AtomicBoolean(true); |
|
|
|
private AtomicBoolean go = new AtomicBoolean(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Writes messages out on a background thread
|
|
|
|
|
|
|
|
private ExecutorService writer = Executors.newFixedThreadPool(1); |
|
|
|
|
|
|
|
|
|
|
|
// Marks the messages as reliable or not if they came
|
|
|
|
// Marks the messages as reliable or not if they came
|
|
|
|
// through this connector.
|
|
|
|
// through this connector.
|
|
|
|
private boolean reliable; |
|
|
|
private boolean reliable; |
|
|
@ -81,6 +86,9 @@ public class ConnectorAdapter extends Thread |
|
|
|
{ |
|
|
|
{ |
|
|
|
go.set(false); |
|
|
|
go.set(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Kill the writer service
|
|
|
|
|
|
|
|
writer.shutdown(); |
|
|
|
|
|
|
|
|
|
|
|
// Kill the connector
|
|
|
|
// Kill the connector
|
|
|
|
connector.close(); |
|
|
|
connector.close(); |
|
|
|
} |
|
|
|
} |
|
|
@ -90,6 +98,11 @@ public class ConnectorAdapter extends Thread |
|
|
|
dispatcher.messageReceived( null, m ); |
|
|
|
dispatcher.messageReceived( null, m ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void write( ByteBuffer data ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
writer.execute( new MessageWriter(data) ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void run() |
|
|
|
public void run() |
|
|
|
{ |
|
|
|
{ |
|
|
|
MessageProtocol protocol = new MessageProtocol(); |
|
|
|
MessageProtocol protocol = new MessageProtocol(); |
|
|
@ -116,4 +129,22 @@ public class ConnectorAdapter extends Thread |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected class MessageWriter implements Runnable |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
private ByteBuffer data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MessageWriter( ByteBuffer data ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this.data = data; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void run() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( !go.get() ) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
connector.write(data); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|