Example usage for java.net InetSocketAddress InetSocketAddress

List of usage examples for java.net InetSocketAddress InetSocketAddress

Introduction

In this page you can find the example usage for java.net InetSocketAddress InetSocketAddress.

Prototype

public InetSocketAddress(int port) 

Source Link

Document

Creates a socket address where the IP address is the wildcard address and the port number a specified value.

Usage

From source file:gridool.communication.transport.nio.GridNioServer.java

private static Selector createSelector(int port) throws IOException {
    final Selector selector = SelectorProvider.provider().openSelector();

    ServerSocketChannel serverChannel = ServerSocketChannel.open();
    serverChannel.configureBlocking(false);

    ServerSocket servSocket = serverChannel.socket();
    servSocket.setReuseAddress(true);//from ww  w .  j a  v a  2 s . c  o  m
    servSocket.bind(new InetSocketAddress(port));

    serverChannel.register(selector, SelectionKey.OP_ACCEPT);

    if (LOG.isInfoEnabled()) {
        LOG.info("GridNioServer is started at port: " + port);
    }
    return selector;
}

From source file:com.buaa.cfs.common.oncrpc.SimpleTcpServer.java

public void run() {
    // Configure the Server.
    ChannelFactory factory;/*from w  w w.j av a 2 s .c o m*/
    if (workerCount == 0) {
        // Use default workers: 2 * the number of available processors
        factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
                Executors.newCachedThreadPool());
    } else {
        factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
                Executors.newCachedThreadPool(), workerCount);
    }

    server = new ServerBootstrap(factory);
    server.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(RpcUtil.constructRpcFrameDecoder(), RpcUtil.STAGE_RPC_MESSAGE_PARSER,
                    rpcProgram, RpcUtil.STAGE_RPC_TCP_RESPONSE);
        }
    });
    server.setOption("child.tcpNoDelay", true);
    server.setOption("child.keepAlive", true);

    // Listen to TCP port
    ch = server.bind(new InetSocketAddress(port));
    InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress();
    boundPort = socketAddr.getPort();

    LOG.info("Started listening to TCP requests at port " + boundPort + " for " + rpcProgram
            + " with workerCount " + workerCount);
}

From source file:org.ow2.chameleon.fuchsia.importer.jsonrpc.it.JSONRPCImporterTest.java

@Before
public void setUpFinal() {
    // instantiate the importer
    Dictionary<String, String> conf = new Hashtable<String, String>();
    conf.put(INSTANCE_NAME_PROPERTY, IMPORTER_NAME);
    conf.put(TARGET_FILTER_PROPERTY, "(" + CONFIGS + "=jsonrpc)");
    ComponentInstance importer = ipojoHelper
            .createComponentInstance("org.ow2.chameleon.fuchsia.importer.jsonrpc.JSONRPCImporter", conf, 20000);
    if (importer == null) {
        fail("Fail to create the JSONRPC Importer.");
    }/* ww  w  .jav  a2s.  co  m*/

    // create HttpServer
    try {
        httpServer = HttpServer.create(new InetSocketAddress(HTTP_PORT), 0);
    } catch (IOException e) {
        fail("Creation of httpServer fail", e);
    }
    httpServer.setExecutor(Executors.newCachedThreadPool());
    httpServer.start();
}

From source file:com.google.enterprise.adaptor.experimental.Sim.java

private void startFeedAcceptor() throws IOException {
    log.info("starting feed acceptor");
    HttpServer server = HttpServer.create();
    int useDefaultBacklog = -1;
    server.bind(new InetSocketAddress(19900), useDefaultBacklog);
    server.createContext("/xmlfeed", new FeedAcceptor());
    server.start();//w w  w  .j ava  2s  .com
    log.info("started feed acceptor");
}

From source file:org.imgedit.webservice.WebServerBootstrap.java

@PostConstruct
private void initialize() {
    if (cliHandler.isParsedSuccessfully()) {
        // Configure the server.
        ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
                Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

        // Set up the pipeline factory.
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(
                        // NOTE: Add "new LoggingHandler(InternalLogLevel.ERROR)," for debug.
                        new HttpRequestDecoder(), new HttpChunkAggregator(MAX_FRAME_SIZE),
                        new HttpResponseEncoder(), new HttpContentCompressor(), webServerHandler);
            }//from w  ww .  j  a v a 2 s  .co  m
        });

        // Bind and start to accept incoming connections.
        LOG.info(String.format("Working in the '%s' directory, listening on the %s port...",
                cliHandler.getBaseDirectory(), cliHandler.getPort()));
        bootstrap.bind(new InetSocketAddress(cliHandler.getPort()));
    }
}

From source file:com.flipkart.phantom.runtime.impl.server.AbstractNetworkServer.java

/**
 * Interface method implementation. Starts up this network server using the specified port
 * @see com.flipkart.phantom.runtime.spi.server.NetworkServer#startServer(int)
 *//*from   w ww .j av a2s  . c  o  m*/
public void startServer(int port) throws RuntimeException {
    this.portNumber = port;
    this.startServer(new InetSocketAddress(portNumber));
}

From source file:com.ibasco.agql.core.AbstractMessage.java

protected final CompareToBuilder compareToBuilder(AbstractMessage<T> rhs) {
    final CompareToBuilder builder = new CompareToBuilder();
    InetSocketAddress lhsSender = defaultIfNull(sender(), new InetSocketAddress(0));
    InetSocketAddress rhsSender = defaultIfNull(rhs.sender(), new InetSocketAddress(0));
    InetSocketAddress lhsReciepient = defaultIfNull(recipient(), new InetSocketAddress(0));
    InetSocketAddress rhsReciepient = defaultIfNull(rhs.recipient(), new InetSocketAddress(0));
    builder.append(lhsSender.getAddress().getHostAddress(), rhsSender.getAddress().getHostAddress());
    builder.append(lhsSender.getPort(), rhsSender.getPort());
    builder.append(lhsReciepient.getAddress().getHostAddress(), rhsReciepient.getAddress().getHostAddress());
    builder.append(lhsReciepient.getPort(), rhsReciepient.getPort());
    builder.append(getClass().getSimpleName(), rhs.getClass().getSimpleName());
    return builder;
}

From source file:org.eclipse.californium.scandium.server.PskDtlsServer.java

public void run(String... arg0) throws Exception {

    InMemoryPskStore pskStore = new InMemoryPskStore();
    LOGGER.log(Level.INFO, "Clients can authenticate to this server using PSK with identity [{0}]",
            clientIdentity);//from   ww w  . ja  v a2s .c o  m
    pskStore.setKey(clientIdentity, clientSecret.getBytes());

    DtlsConnectorConfig config = new DtlsConnectorConfig.Builder(new InetSocketAddress(port))
            .setPskStore(pskStore).setMaxFragmentLengthCode(3).build();
    ConnectionStore connectionStore = new InMemoryConnectionStore(maxConnections, 60);
    dtlsConnector = new DTLSConnector(config, connectionStore);
    dtlsConnector.setRawDataReceiver(new RawDataChannelImpl(dtlsConnector));

    dtlsConnector.start();
}

From source file:com.github.brandtg.switchboard.FileLogAggregator.java

/**
 * An agent that aggregates logs from multiple sources and multiplexes them.
 *
 * @param sources//  ww w.ja  v  a  2 s  .c o  m
 *  A set of source switchboard servers from which to pull logs
 * @param separator
 *  The line delimiter (after this is reached, lines will be output to outputStream)
 * @param outputStream
 *  OutputStream to which all multiplexed logs are piped
 */
public FileLogAggregator(Set<InetSocketAddress> sources, char separator, OutputStream outputStream)
        throws IOException {
    this.separator = separator;
    this.outputStream = outputStream;
    this.isShutdown = new AtomicBoolean(true);
    this.eventExecutors = new NioEventLoopGroup();
    this.logReceivers = new HashMap<>();
    this.inputStreams = new HashMap<>();
    this.listener = new Object();
    this.muxExecutor = Executors.newSingleThreadExecutor();
    this.stringBuffers = new HashMap<>();

    for (InetSocketAddress source : sources) {
        PipedOutputStream pos = new PipedOutputStream();
        PipedInputStream pis = new PipedInputStream(pos);
        LogReceiver logReceiver = new LogReceiver(new InetSocketAddress(0), eventExecutors, pos);
        logReceiver.registerListener(listener);
        logReceivers.put(source, logReceiver);
        inputStreams.put(source, pis);
        stringBuffers.put(source, new StringBuffer());
    }
}

From source file:org.keycloak.testsuite.oauth.OAuthRedirectUriTest.java

@Override
public void beforeAbstractKeycloakTest() throws Exception {
    super.beforeAbstractKeycloakTest();

    server = HttpServer.create(new InetSocketAddress(8280), 0);
    server.createContext("/", new MyHandler());
    server.setExecutor(null); // creates a default executor
    server.start();//from  w w w  . j a va2  s.  c  o m
}