@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; }
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; }
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); }
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; }
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); }
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); }
@Override public <PART> PART getPart(int partId, Class<PART> partClass) { return ObjectSpace.getRemoteObject(client, partId, partClass); }
public RemoveConnectionListener(final ObjectSpace objectSpace) { Validate.notNull(objectSpace); this.objectSpace = objectSpace; }
public MyServer(final ObjectSpace objectSpace) { Validate.notNull(objectSpace); this.objectSpace = objectSpace; RemoveConnectionListener _removeConnectionListener = new RemoveConnectionListener(objectSpace); this.addListener(_removeConnectionListener); }
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(); }
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); }
protected void setup(Kryo kryo) { kryo.setRegistrationRequired(true); ObjectSpace.registerClasses(kryo); kryo.setDefaultSerializer(new ConfiguringSerializerFactory()); registerArrays(kryo); registerCollections(kryo); registerJvmClasses(kryo); registerFrameworkClasses(kryo); }
public KryonetConnectionClient(Connection connection) { super(); this.connection = connection; objectSpace = new ObjectSpace(connection); }