List of usage examples for java.nio.channels DatagramChannel register
public final SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException
From source file:org.apache.axis2.transport.udp.IODispatcher.java
/** * Add a new endpoint. This method creates a new socket listening on * the UDP port specified in the endpoint description and makes sure * that incoming packets are routed to the specified service. * /*from w ww . java2s . c om*/ * @param endpoint the endpoint description * @throws IOException if the socket could not be created or * registered with the selector */ public void addEndpoint(final Endpoint endpoint) throws IOException { final DatagramChannel channel = DatagramChannel.open(); channel.socket().bind(new InetSocketAddress(endpoint.getPort())); channel.configureBlocking(false); execute(new SelectorOperation() { @Override public void doExecute(Selector selector) throws IOException { channel.register(selector, SelectionKey.OP_READ, endpoint); } }); log.info("UDP endpoint started on port : " + endpoint.getPort()); }
From source file:org.apache.synapse.transport.udp.IODispatcher.java
/** * Add a new endpoint. This method creates a new socket listening on * the UDP port specified in the endpoint description and makes sure * that incoming packets are routed to the specified service. * /*from w w w . ja v a 2 s . c o m*/ * @param endpoint the endpoint description * @throws IOException if the socket could not be created or * registered with the selector */ public void addEndpoint(final Endpoint endpoint) throws IOException { final DatagramChannel channel = DatagramChannel.open(); channel.socket().bind(new InetSocketAddress(endpoint.getPort())); channel.configureBlocking(false); execute(new SelectorOperation() { @Override public void doExecute(Selector selector) throws IOException { channel.register(selector, SelectionKey.OP_READ, endpoint); } }); }