Search in sources :

Example 6 with SocketException

use of java.net.SocketException in project zookeeper by apache.

the class QuorumPeer method startLeaderElection.

public synchronized void startLeaderElection() {
    try {
        if (getPeerState() == ServerState.LOOKING) {
            currentVote = new Vote(myid, getLastLoggedZxid(), getCurrentEpoch());
        }
    } catch (IOException e) {
        RuntimeException re = new RuntimeException(e.getMessage());
        re.setStackTrace(e.getStackTrace());
        throw re;
    }
    //}
    if (electionType == 0) {
        try {
            udpSocket = new DatagramSocket(myQuorumAddr.getPort());
            responder = new ResponderThread();
            responder.start();
        } catch (SocketException e) {
            throw new RuntimeException(e);
        }
    }
    this.electionAlg = createElectionAlgorithm(electionType);
}
Also used : SocketException(java.net.SocketException) DatagramSocket(java.net.DatagramSocket) IOException(java.io.IOException)

Example 7 with SocketException

use of java.net.SocketException in project weave by continuuity.

the class SocketServer method run.

@Override
public void run() {
    try {
        runThread = Thread.currentThread();
        while (running) {
            try {
                Socket socket = serverSocket.accept();
                try {
                    BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
                    PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
                    handleRequest(reader, writer);
                } finally {
                    socket.close();
                }
            } catch (SocketException e) {
                LOG.info("Socket exception: " + e);
            }
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : SocketException(java.net.SocketException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) SocketException(java.net.SocketException) PrintWriter(java.io.PrintWriter)

Example 8 with SocketException

use of java.net.SocketException in project cw-omnibus by commonsguy.

the class WebServerService method raiseReadyEvent.

private void raiseReadyEvent() {
    ServerStartedEvent event = new ServerStartedEvent();
    try {
        for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
            NetworkInterface ni = enInterfaces.nextElement();
            for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
                InetAddress addr = enAddresses.nextElement();
                if (addr instanceof Inet4Address) {
                    event.addUrl("http://" + addr.getHostAddress() + ":4999" + rootPath + "/");
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    EventBus.getDefault().removeAllStickyEvents();
    EventBus.getDefault().postSticky(event);
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 9 with SocketException

use of java.net.SocketException in project cw-omnibus by commonsguy.

the class WebServerService method raiseReadyEvent.

private void raiseReadyEvent() {
    ServerStartedEvent event = new ServerStartedEvent();
    try {
        for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
            NetworkInterface ni = enInterfaces.nextElement();
            for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
                InetAddress addr = enAddresses.nextElement();
                if (addr instanceof Inet4Address) {
                    event.addUrl("http://" + addr.getHostAddress() + ":4999" + rootPath + "/");
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    EventBus.getDefault().removeAllStickyEvents();
    EventBus.getDefault().postSticky(event);
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 10 with SocketException

use of java.net.SocketException in project cw-omnibus by commonsguy.

the class WebServerService method raiseStartedEvent.

private void raiseStartedEvent() {
    ServerStartedEvent event = new ServerStartedEvent();
    try {
        for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
            NetworkInterface ni = enInterfaces.nextElement();
            for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
                InetAddress addr = enAddresses.nextElement();
                if (addr instanceof Inet4Address) {
                    event.addUrl("http://" + addr.getHostAddress() + ":4999");
                }
            }
        }
    } catch (SocketException e) {
        Log.e(getClass().getSimpleName(), "Exception in IP addresses", e);
    }
    EventBus.getDefault().removeAllStickyEvents();
    EventBus.getDefault().postSticky(event);
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Aggregations

SocketException (java.net.SocketException)925 IOException (java.io.IOException)349 InetAddress (java.net.InetAddress)254 NetworkInterface (java.net.NetworkInterface)240 UnknownHostException (java.net.UnknownHostException)153 Socket (java.net.Socket)146 SocketTimeoutException (java.net.SocketTimeoutException)118 ServerSocket (java.net.ServerSocket)114 DatagramSocket (java.net.DatagramSocket)95 Test (org.junit.Test)87 InetSocketAddress (java.net.InetSocketAddress)84 ArrayList (java.util.ArrayList)70 Inet4Address (java.net.Inet4Address)51 DatagramPacket (java.net.DatagramPacket)49 ConnectException (java.net.ConnectException)48 InputStream (java.io.InputStream)41 InterruptedIOException (java.io.InterruptedIOException)41 BindException (java.net.BindException)36 EOFException (java.io.EOFException)33 OutputStream (java.io.OutputStream)32