/** * Creates a new UDP connector. * * @param address the address * @param config the configuration * @return the connector */ private static Connector createUDPConnector(final InetSocketAddress address, final NetworkConfig config) { UDPConnector c = new UDPConnector(address); c.setReceiverThreadCount(config.getInt(NetworkConfig.Keys.NETWORK_STAGE_RECEIVER_THREAD_COUNT)); c.setSenderThreadCount(config.getInt(NetworkConfig.Keys.NETWORK_STAGE_SENDER_THREAD_COUNT)); c.setReceiveBufferSize(config.getInt(NetworkConfig.Keys.UDP_CONNECTOR_RECEIVE_BUFFER)); c.setSendBufferSize(config.getInt(NetworkConfig.Keys.UDP_CONNECTOR_SEND_BUFFER)); c.setReceiverPacketSize(config.getInt(NetworkConfig.Keys.UDP_CONNECTOR_DATAGRAM_SIZE)); return c; }
public void destroy() { if (connector != null) { connector.destroy(); } }
public LockstepEndpoint(final InetSocketAddress destination) { this.destination = destination; this.storage = new HashMap<String, Object>(); this.incoming = new LinkedBlockingQueue<RawData>(); this.connector = new UDPConnector(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); this.connector.setRawDataReceiver(new RawDataChannel() { public void receiveData(RawData raw) { incoming.offer(raw); } }); this.serializer = new UdpDataSerializer(); this.parser = new UdpDataParser(); try { connector.start(); // Thread.sleep(100); } catch (Exception e) { throw new RuntimeException(e); } }
public InetAddress getAddress() { return connector.getAddress().getAddress(); }
public void send(RawData raw) { if (raw.getAddress() == null || raw.getPort() == 0) { throw new RuntimeException("Message has no destination address/port"); } connector.send(raw); }
public int getPort() { return connector.getAddress().getPort(); }
/** * Creates a new UDP connector. * * @param address the address * @param config the configuration * @return the connector */ private static Connector createUDPConnector(InetSocketAddress address, NetworkConfig config) { UDPConnector c = new UDPConnector(address); c.setReceiverThreadCount(config.getInt(NetworkConfig.Keys.NETWORK_STAGE_RECEIVER_THREAD_COUNT)); c.setSenderThreadCount(config.getInt(NetworkConfig.Keys.NETWORK_STAGE_SENDER_THREAD_COUNT)); c.setReceiveBufferSize(config.getInt(NetworkConfig.Keys.UDP_CONNECTOR_RECEIVE_BUFFER)); c.setSendBufferSize(config.getInt(NetworkConfig.Keys.UDP_CONNECTOR_SEND_BUFFER)); c.setReceiverPacketSize(config.getInt(NetworkConfig.Keys.UDP_CONNECTOR_DATAGRAM_SIZE)); return c; }