Modified KernelAdapter to be a more self-sufficient adapter
to better support having multiple channels. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8933 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
48db901b5b
commit
5cb7e21157
@ -60,9 +60,7 @@ public class DefaultServer implements Server
|
|||||||
private AtomicInteger nextId = new AtomicInteger(0);
|
private AtomicInteger nextId = new AtomicInteger(0);
|
||||||
private String gameName;
|
private String gameName;
|
||||||
private int version;
|
private int version;
|
||||||
private Kernel reliable;
|
|
||||||
private KernelAdapter reliableAdapter;
|
private KernelAdapter reliableAdapter;
|
||||||
private Kernel fast;
|
|
||||||
private KernelAdapter fastAdapter;
|
private KernelAdapter fastAdapter;
|
||||||
private Redispatch dispatcher = new Redispatch();
|
private Redispatch dispatcher = new Redispatch();
|
||||||
private Map<Integer,HostedConnection> connections = new ConcurrentHashMap<Integer,HostedConnection>();
|
private Map<Integer,HostedConnection> connections = new ConcurrentHashMap<Integer,HostedConnection>();
|
||||||
@ -84,8 +82,6 @@ public class DefaultServer implements Server
|
|||||||
|
|
||||||
this.gameName = gameName;
|
this.gameName = gameName;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.reliable = reliable;
|
|
||||||
this.fast = fast;
|
|
||||||
|
|
||||||
reliableAdapter = new KernelAdapter( this, reliable, dispatcher, true );
|
reliableAdapter = new KernelAdapter( this, reliable, dispatcher, true );
|
||||||
if( fast != null ) {
|
if( fast != null ) {
|
||||||
@ -109,9 +105,9 @@ public class DefaultServer implements Server
|
|||||||
throw new IllegalStateException( "Server is already started." );
|
throw new IllegalStateException( "Server is already started." );
|
||||||
|
|
||||||
// Initialize the kernels
|
// Initialize the kernels
|
||||||
reliable.initialize();
|
reliableAdapter.initialize();
|
||||||
if( fast != null ) {
|
if( fastAdapter != null ) {
|
||||||
fast.initialize();
|
fastAdapter.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start em up
|
// Start em up
|
||||||
@ -161,12 +157,12 @@ public class DefaultServer implements Server
|
|||||||
FilterAdapter adapter = filter == null ? null : new FilterAdapter(filter);
|
FilterAdapter adapter = filter == null ? null : new FilterAdapter(filter);
|
||||||
|
|
||||||
// Ignore the filter for the moment
|
// Ignore the filter for the moment
|
||||||
if( message.isReliable() || fast == null ) {
|
if( message.isReliable() || fastAdapter == null ) {
|
||||||
// Don't need to copy the data because message protocol is already
|
// Don't need to copy the data because message protocol is already
|
||||||
// giving us a fresh buffer
|
// giving us a fresh buffer
|
||||||
reliable.broadcast( adapter, buffer, true, false );
|
reliableAdapter.broadcast( adapter, buffer, true, false );
|
||||||
} else {
|
} else {
|
||||||
fast.broadcast( adapter, buffer, false, false );
|
fastAdapter.broadcast( adapter, buffer, false, false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
package com.jme3.network.base;
|
package com.jme3.network.base;
|
||||||
|
|
||||||
|
import com.jme3.network.Filter;
|
||||||
import com.jme3.network.HostedConnection;
|
import com.jme3.network.HostedConnection;
|
||||||
import com.jme3.network.Message;
|
import com.jme3.network.Message;
|
||||||
import com.jme3.network.MessageListener;
|
import com.jme3.network.MessageListener;
|
||||||
@ -89,6 +90,22 @@ public class KernelAdapter extends Thread
|
|||||||
this.reliable = reliable;
|
this.reliable = reliable;
|
||||||
setDaemon(true);
|
setDaemon(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Kernel getKernel()
|
||||||
|
{
|
||||||
|
return kernel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize()
|
||||||
|
{
|
||||||
|
kernel.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcast( Filter<? super Endpoint> filter, ByteBuffer data, boolean reliable,
|
||||||
|
boolean copy )
|
||||||
|
{
|
||||||
|
kernel.broadcast( filter, data, reliable, copy );
|
||||||
|
}
|
||||||
|
|
||||||
public void close() throws InterruptedException
|
public void close() throws InterruptedException
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ import com.jme3.network.AbstractMessage;
|
|||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client registration is a message that contains a unique ID. This ID
|
* Client registration is a message that contains a unique ID. This ID
|
||||||
* is simply the current time in milliseconds, providing multiple clients
|
* is simply the current time in milliseconds, providing multiple clients
|
||||||
* will not connect to the same server within one millisecond. This is used
|
* will not connect to the same server within one millisecond. This is used
|
||||||
* to couple the TCP and UDP connections together into one 'Client' on the
|
* to couple the TCP and UDP connections together into one 'Client' on the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user