Example usage for java.net ServerSocket getLocalSocketAddress

List of usage examples for java.net ServerSocket getLocalSocketAddress

Introduction

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

Prototype


public SocketAddress getLocalSocketAddress() 

Source Link

Document

Returns the address of the endpoint this socket is bound to.

Usage

From source file:org.apache.stratos.python.cartridge.agent.test.PythonAgentTestManager.java

/**
 * TearDown method for test method testPythonCartridgeAgent
 *//*from w  ww  .  j  ava2 s .  c o m*/
protected void tearDown(String sourcePath) {
    for (Map.Entry<String, Executor> entry : executorList.entrySet()) {
        try {
            String commandText = entry.getKey();
            Executor executor = entry.getValue();
            log.info("Terminating process: " + commandText);
            executor.setExitValue(0);
            executor.getWatchdog().destroyProcess();
        } catch (Exception ignore) {
        }
    }
    // wait until everything cleans up to avoid connection errors
    sleep(1000);
    for (ServerSocket serverSocket : serverSocketMap.values()) {
        try {
            log.info("Stopping socket server: " + serverSocket.getLocalSocketAddress());
            serverSocket.close();
        } catch (IOException ignore) {
        }
    }
    try {
        if (thriftTestServer != null) {
            thriftTestServer.stop();
        }
    } catch (Exception e) {
        log.error("Could not stop Thrift test server", e);
    }

    try {
        log.info("Deleting source checkout folder...");
        FileUtils.deleteDirectory(new File(sourcePath));
    } catch (Exception ignore) {
    }
    this.instanceStatusEventReceiver.terminate();
    this.topologyEventReceiver.terminate();

    this.instanceActivated = false;
    this.instanceStarted = false;
    try {
        broker.stop();
    } catch (Exception e) {
        log.error("Error while stopping the broker service", e);
    }
}

From source file:org.apache.stratos.python.cartridge.agent.test.PythonCartridgeAgentTest.java

/**
 * TearDown method for test method testPythonCartridgeAgent
 *///from   w  w  w . j a  v  a2 s.  c  o  m
@After
public void tearDown() {
    for (Map.Entry<String, Executor> entry : executorList.entrySet()) {
        try {
            String commandText = entry.getKey();
            Executor executor = entry.getValue();
            ExecuteWatchdog watchdog = executor.getWatchdog();
            if (watchdog != null) {
                log.info("Terminating process: " + commandText);
                watchdog.destroyProcess();
            }
            File workingDirectory = executor.getWorkingDirectory();
            if (workingDirectory != null) {
                log.info("Cleaning working directory: " + workingDirectory.getAbsolutePath());
                FileUtils.deleteDirectory(workingDirectory);
            }
        } catch (Exception ignore) {
        }
    }
    for (ServerSocket serverSocket : serverSocketList) {
        try {
            log.info("Stopping socket server: " + serverSocket.getLocalSocketAddress());
            serverSocket.close();
        } catch (IOException ignore) {
        }
    }

    try {
        log.info("Deleting source checkout folder...");
        FileUtils.deleteDirectory(new File(SOURCE_PATH));
    } catch (Exception ignore) {

    }

    this.instanceStatusEventReceiver.terminate();
    this.topologyEventReceiver.terminate();

    this.instanceActivated = false;
    this.instanceStarted = false;
}

From source file:pt.minha.calibration.Calibrator.java

private static void runServer() throws Exception {
    // Reality server
    ServerSocket ss = new ServerSocket(12345);

    logger.info("server: started at {}", ss.getLocalSocketAddress());

    while (true) {
        Socket s = ss.accept();/*from w w w.  ja  v  a 2 s.  c  om*/

        logger.info("server: accepted {}", s.getRemoteSocketAddress());

        try {
            ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(s.getOutputStream()));
            oos.flush();
            ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(s.getInputStream()));

            while (!s.isClosed()) {
                Map<String, Object> p = (Map<String, Object>) ois.readObject();
                Benchmark next = (Benchmark) Class.forName((String) p.get("bench")).newInstance();
                next.setParameters(p);

                logger.info("server: running {}", p);

                Object result = next.server();

                logger.info("server: running {} done", p);

                oos.writeObject(result);
                oos.flush();
            }

            logger.info("server: disconnected {}", s.getRemoteSocketAddress());

        } catch (IOException ioe) {
            logger.info("server: disconnected {} on {}", s.getRemoteSocketAddress(), ioe);
        }
    }
}