Java 类com.esotericsoftware.kryonet.rmi.ObjectSpace 实例源码

项目:quadracoatl    文件:KryonetServer.java   
@Override
public <PART> PART getPart(int partId, Class<PART> partClass) {
    PART part = super.getPart(partId, partClass);

    if (part == null) {
        part = ObjectSpace.getRemoteObject(connection, partId, partClass);

        if (part != null) {
            super.putPart(partId, part);

            if (partId == EntityEventReceiver.ID) {
                makeAsynchron((RemoteObject)part);
            }
        }
    }

    return part;
}
项目:abattle    文件:NetworkServerImpl.java   
public NetworkServerImpl(final NetworkConfigurationData configuration) {
  Validate.notNull(configuration);
  this.configuration = configuration;
  ObjectSpace _objectSpace = new ObjectSpace();
  this.objectSpace = _objectSpace;
  MyServer _myServer = new MyServer(this.objectSpace);
  this.server = _myServer;
  Kryo _kryo = this.server.getKryo();
  ObjectSpace.registerClasses(_kryo);
  Kryo _kryo_1 = this.server.getKryo();
  SerializerHelper.initializeKryo(_kryo_1);
  this.sentBytes = 0L;
  long _currentTimeMillis = System.currentTimeMillis();
  this.lastLog = _currentTimeMillis;
  MyHashMap<Integer, NetworkService> _myHashMap = new MyHashMap<Integer, NetworkService>();
  this.serviceMap = _myHashMap;
  HashSet<Listener> _newHashSet = CollectionLiterals.<Listener>newHashSet();
  this.listeners = _newHashSet;
}
项目:abattle    文件:NetworkClientImpl.java   
public NetworkClientImpl(final NetworkConfigurationData configuration) {
  Validate.notNull(configuration);
  this.configuration = configuration;
  Client _client = new Client();
  this.client = _client;
  Kryo _kryo = this.client.getKryo();
  ObjectSpace.registerClasses(_kryo);
  Optional<NetworkGameInfo> _absent = Optional.<NetworkGameInfo>absent();
  this.gameFound = _absent;
  Optional<ServerService> _absent_1 = Optional.<ServerService>absent();
  this.serverService = _absent_1;
  LifecycleControl _control = LifecycleControl.getControl();
  _control.addStopListener(this);
}
项目:abattle    文件:NetworkClientImpl.java   
private Optional<ServerService> getRemoteServerService() {
  Optional<ServerService> _xblockexpression = null;
  {
    final ServerService someObject = ObjectSpace.<ServerService>getRemoteObject(this.client, ServerService.SERVER_SERVICE_ID, ServerService.class);
    ((RemoteObject) someObject).setNonBlocking(false);
    Optional<ServerService> _fromNullable = Optional.<ServerService>fromNullable(someObject);
    _xblockexpression = this.serverService = _fromNullable;
  }
  return _xblockexpression;
}
项目:kingdom    文件:ChatRmiServer.java   
public Player () {
    // Each connection has an ObjectSpace containing the Player.
    // This allows the other end of the connection to call methods on the Player.
    new ObjectSpace(this).register(Network.PLAYER, this);
    // Get the ChatFrame on the other end of the connection.
    // This allows the server to call methods on the client.
    frame = ObjectSpace.getRemoteObject(this, Network.CHAT_FRAME, IChatFrame.class);
}
项目:kingdom    文件:Network.java   
static public void register (EndPoint endPoint) {
    Kryo kryo = endPoint.getKryo();
    // This must be called in order to use ObjectSpaces.
    ObjectSpace.registerClasses(kryo);
    // The interfaces that will be used as remote objects must be registered.
    kryo.register(IPlayer.class);
    kryo.register(IChatFrame.class);
    // The classes of all method parameters and return values
    // for remote objects must also be registered.
    kryo.register(String[].class);
}
项目:kryonet    文件:ChatRmiServer.java   
public Player () {
    // Each connection has an ObjectSpace containing the Player.
    // This allows the other end of the connection to call methods on the Player.
    new ObjectSpace(this).register(Network.PLAYER, this);
    // Get the ChatFrame on the other end of the connection.
    // This allows the server to call methods on the client.
    frame = ObjectSpace.getRemoteObject(this, Network.CHAT_FRAME, IChatFrame.class);
}
项目:kryonet    文件:Network.java   
static public void register (EndPoint endPoint) {
    Kryo kryo = endPoint.getKryo();
    // This must be called in order to use ObjectSpaces.
    ObjectSpace.registerClasses(kryo);
    // The interfaces that will be used as remote objects must be registered.
    kryo.register(IPlayer.class);
    kryo.register(IChatFrame.class);
    // The classes of all method parameters and return values
    // for remote objects must also be registered.
    kryo.register(String[].class);
}
项目:quadracoatl    文件:KryonetClient.java   
@Override
public <PART> PART getPart(int partId, Class<PART> partClass) {
    return ObjectSpace.getRemoteObject(client, partId, partClass);
}
项目:abattle    文件:RemoveConnectionListener.java   
public RemoveConnectionListener(final ObjectSpace objectSpace) {
  Validate.notNull(objectSpace);
  this.objectSpace = objectSpace;
}
项目:abattle    文件:MyServer.java   
public MyServer(final ObjectSpace objectSpace) {
  Validate.notNull(objectSpace);
  this.objectSpace = objectSpace;
  RemoveConnectionListener _removeConnectionListener = new RemoveConnectionListener(objectSpace);
  this.addListener(_removeConnectionListener);
}
项目:kingdom    文件:ChatRmiClient.java   
public ChatRmiClient () {
    client = new Client();
    client.start();

    // Register the classes that will be sent over the network.
    Network.register(client);

    // Get the Player on the other end of the connection.
    // This allows the client to call methods on the server.
    player = ObjectSpace.getRemoteObject(client, Network.PLAYER, IPlayer.class);

    client.addListener(new Listener() {
        public void disconnected (Connection connection) {
            EventQueue.invokeLater(new Runnable() {
                public void run () {
                    // Closing the frame calls the close listener which will stop the client's update thread.
                    chatFrame.dispose();
                }
            });
        }
    });

    // Request the host from the user.
    String input = (String)JOptionPane.showInputDialog(null, "Host:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE,
        null, null, "localhost");
    if (input == null || input.trim().length() == 0) System.exit(1);
    final String host = input.trim();

    // Request the user's name.
    input = (String)JOptionPane.showInputDialog(null, "Name:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE, null,
        null, "Test");
    if (input == null || input.trim().length() == 0) System.exit(1);
    final String name = input.trim();

    // The chat frame contains all the Swing stuff.
    chatFrame = new ChatFrame(host);
    // Register the chat frame so the server can call methods on it.
    new ObjectSpace(client).register(Network.CHAT_FRAME, chatFrame);
    // This listener is called when the send button is clicked.
    chatFrame.setSendListener(new Runnable() {
        public void run () {
            player.sendMessage(chatFrame.getSendText());
        }
    });
    // This listener is called when the chat window is closed.
    chatFrame.setCloseListener(new Runnable() {
        public void run () {
            client.stop();
        }
    });
    chatFrame.setVisible(true);

    // We'll do the connect on a new thread so the ChatFrame can show a progress bar.
    // Connecting to localhost is usually so fast you won't see the progress bar.
    new Thread("Connect") {
        public void run () {
            try {
                client.connect(5000, host, Network.port);
                // Server communication after connection can go here, or in Listener#connected().
                player.registerName(name);
            } catch (IOException ex) {
                ex.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
项目:kryonet    文件:ChatRmiClient.java   
public ChatRmiClient () {
    client = new Client();
    client.start();

    // Register the classes that will be sent over the network.
    Network.register(client);

    // Get the Player on the other end of the connection.
    // This allows the client to call methods on the server.
    player = ObjectSpace.getRemoteObject(client, Network.PLAYER, IPlayer.class);

    client.addListener(new Listener() {
        public void disconnected (Connection connection) {
            EventQueue.invokeLater(new Runnable() {
                public void run () {
                    // Closing the frame calls the close listener which will stop the client's update thread.
                    chatFrame.dispose();
                }
            });
        }
    });

    // Request the host from the user.
    String input = (String)JOptionPane.showInputDialog(null, "Host:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE,
        null, null, "localhost");
    if (input == null || input.trim().length() == 0) System.exit(1);
    final String host = input.trim();

    // Request the user's name.
    input = (String)JOptionPane.showInputDialog(null, "Name:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE, null,
        null, "Test");
    if (input == null || input.trim().length() == 0) System.exit(1);
    final String name = input.trim();

    // The chat frame contains all the Swing stuff.
    chatFrame = new ChatFrame(host);
    // Register the chat frame so the server can call methods on it.
    new ObjectSpace(client).register(Network.CHAT_FRAME, chatFrame);
    // This listener is called when the send button is clicked.
    chatFrame.setSendListener(new Runnable() {
        public void run () {
            player.sendMessage(chatFrame.getSendText());
        }
    });
    // This listener is called when the chat window is closed.
    chatFrame.setCloseListener(new Runnable() {
        public void run () {
            client.stop();
        }
    });
    chatFrame.setVisible(true);

    // We'll do the connect on a new thread so the ChatFrame can show a progress bar.
    // Connecting to localhost is usually so fast you won't see the progress bar.
    new Thread("Connect") {
        public void run () {
            try {
                client.connect(5000, host, Network.port);
                // Server communication after connection can go here, or in Listener#connected().
                player.registerName(name);
            } catch (IOException ex) {
                ex.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
项目:quadracoatl    文件:KryonetClient.java   
public KryonetClient(String serverAddress, int tcpPort, int udpPort) {
    super();

    this.serverAddress = serverAddress;
    this.tcpPort = tcpPort;

    this.udpPort = udpPort;

    client = new Client(DEFAULT_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);

    kryo = client.getKryo();
    setup(kryo);

    objectSpace = new ObjectSpace(client);
}
项目:quadracoatl    文件:AbstractKryoBase.java   
protected void setup(Kryo kryo) {
    kryo.setRegistrationRequired(true);

    ObjectSpace.registerClasses(kryo);

    kryo.setDefaultSerializer(new ConfiguringSerializerFactory());

    registerArrays(kryo);
    registerCollections(kryo);
    registerJvmClasses(kryo);

    registerFrameworkClasses(kryo);
}
项目:quadracoatl    文件:KryonetServer.java   
public KryonetConnectionClient(Connection connection) {
    super();

    this.connection = connection;

    objectSpace = new ObjectSpace(connection);
}