Example usage for java.net Socket isClosed

List of usage examples for java.net Socket isClosed

Introduction

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

Prototype

public boolean isClosed() 

Source Link

Document

Returns the closed state of the socket.

Usage

From source file:com.alphabetbloc.accessmrs.utilities.MySSLSocketFactory.java

@Override
public boolean isSecure(Socket sock) throws IllegalArgumentException {
    if (sock == null) {
        throw new IllegalArgumentException("Socket may not be null.");
    }/*from   ww w  .j  a  v a2s . c  om*/

    if (!(sock instanceof SSLSocket)) {
        throw new IllegalArgumentException("Socket not created by this factory.");
    }

    if (sock.isClosed()) {
        throw new IllegalArgumentException("Socket is closed.");
    }
    return true;
}

From source file:org.openqa.selenium.remote.ReusingSocketSocketFactory.java

/**
 * Checks whether a socket connection is secure.
 * This factory creates plain socket connections
 * which are not considered secure.//from  ww w.jav  a 2 s .  c o  m
 *
 * @param sock      the connected socket
 *
 * @return  <code>false</code>
 *
 * @throws IllegalArgumentException if the argument is invalid
 */
public final boolean isSecure(Socket sock) throws IllegalArgumentException {

    if (sock == null) {
        throw new IllegalArgumentException("Socket may not be null.");
    }
    // This check is performed last since it calls a method implemented
    // by the argument object. getClass() is final in java.lang.Object.
    if (sock.isClosed()) {
        throw new IllegalArgumentException("Socket is closed.");
    }
    return false;
}

From source file:com.rovemonteux.silvertunnel.netlib.adapter.httpclient.NetlibSocketFactory.java

/**
 * Checks whether a socket connection is secure. This factory creates plain
 * socket connections which are not considered secure.
 * /* ww w .  j  a  v a  2 s  .c  o  m*/
 * @param sock
 *            the connected socket
 * 
 * @return <code>false</code>
 * 
 * @throws IllegalArgumentException
 *             if the argument is invalid
 */
@Override
public final boolean isSecure(final Socket sock) throws IllegalArgumentException {

    if (sock == null) {
        throw new IllegalArgumentException("Socket may not be null.");
    }
    // This check is performed last since it calls a method implemented
    // by the argument object. getClass() is final in java.lang.Object.
    if (sock.isClosed()) {
        throw new IllegalArgumentException("Socket is closed.");
    }
    return false;
}

From source file:com.mgmtp.perfload.core.client.web.ssl.LtSSLSocketFactory.java

@Override
public boolean isSecure(final Socket socket) throws IllegalArgumentException {
    checkArgument(socket != null, "Socket may not be null");
    checkArgument(socket instanceof SSLSocket, "Socket not created by this factory");
    checkArgument(!socket.isClosed(), "Socket is closed");
    return true;/*from   w ww  .  j  a  v a 2s . c o  m*/
}

From source file:com.plotsquared.iserver.core.Worker.java

/**
 * Accepts a remote socket,/*from w  w  w. j  a  v  a2s  .  co m*/
 * makes sure its handled and closed down successfully
 * @param remote Socket to accept
 */
public void run(final Socket remote) {
    if (remote != null && !remote.isClosed()) {
        handle(remote);
    }
    if (remote != null && !remote.isClosed()) {
        try {
            remote.close();
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
    // MUST BE CALLED LAST
    availableWorkers.add(this);
}

From source file:org.eclipse.mylyn.internal.commons.http.PollingSslProtocolSocketFactory.java

/**
 * From SSLSocketFactory// w  w w . j  a  va  2  s  . c om
 */
public boolean isSecure(Socket sock) throws IllegalArgumentException {
    if (sock == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    // This instanceof check is in line with createSocket() above.
    if (!(sock instanceof SSLSocket)) {
        throw new IllegalArgumentException("Socket not created by this factory");
    }
    // This check is performed last since it calls the argument object.
    if (sock.isClosed()) {
        throw new IllegalArgumentException("Socket is closed");
    }
    return true;
}

From source file:org.mule.transport.tcp.TcpConnector.java

/**
 * Lookup a socket in the list of dispatcher sockets but don't create a new
 * socket//w  w  w  .j  av  a 2s. c  om
 */
protected Socket getSocket(ImmutableEndpoint endpoint) throws Exception {
    TcpSocketKey socketKey = new TcpSocketKey(endpoint);
    if (logger.isDebugEnabled()) {
        logger.debug("borrowing socket for " + socketKey + "/" + socketKey.hashCode());
        if (null != lastSocketKey) {
            logger.debug("same as " + lastSocketKey.hashCode() + "? " + lastSocketKey.equals(socketKey));
        }
    }
    Socket socket = (Socket) socketsPool.borrowObject(socketKey);
    if (logger.isDebugEnabled()) {
        logger.debug("borrowed socket, " + (socket.isClosed() ? "closed" : "open") + "; debt "
                + socketsPool.getNumActive());
    }
    return socket;
}

From source file:com.mirth.connect.connectors.tcp.TcpDispatcher.java

private void closeSocket(String socketKey) throws IOException {
    Socket socket = connectedSockets.get(socketKey);
    if (socket != null) {
        boolean wasOpen = !socket.isClosed();
        try {//from   ww  w .j av a  2  s.  com
            if (wasOpen) {
                logger.trace("Closing socket (" + connectorProperties.getName() + " \"" + getDestinationName()
                        + "\" on channel " + getChannelId() + ").");
                SocketUtil.closeSocket(socket);
            }
        } finally {
            connectedSockets.remove(socketKey);

            if (wasOpen) {
                eventController.dispatchEvent(new ConnectorCountEvent(getChannelId(), getMetaDataId(),
                        getDestinationName(), ConnectionStatusEventType.DISCONNECTED,
                        SocketUtil.getLocalAddress(socket) + " -> " + SocketUtil.getInetAddress(socket),
                        false));
            }
        }
    }
}

From source file:com.inmobi.messaging.util.GraphiteStatsEmitter.java

protected void writeStats() {
    if (null != statsExposers) {
        synchronized (statsExposers) {
            final StringBuilder lines = new StringBuilder();
            long timestamp = System.currentTimeMillis() / 1000;
            for (StatsExposer exposer : statsExposers) {
                Map<String, Number> stats = exposer.getStats();
                Map<String, String> context = exposer.getContexts();
                String topic = context.get(TopicStatsExposer.TOPIC_CONTEXT_NAME);
                /**//from w  ww .  ja va2 s  . c o m
                 * Publisher will be having topic set as category in the statsexposer,
                 * but for consumers topic is set as topicName for the statsexposer.
                 */
                if (null == topic) {
                    topic = context.get(MessageConsumerMetricsConstants.TOPIC_CONTEXT);
                }
                for (Map.Entry<String, Number> entry : stats.entrySet()) {
                    lines.append(metricPrefix).append(topic).append(METRIC_SEPARATOR).append(entry.getKey());
                    lines.append(FIELD_SEPARATOR);
                    lines.append(entry.getValue().longValue());
                    lines.append(FIELD_SEPARATOR);
                    lines.append(timestamp);
                    lines.append(NEW_LINE);
                }
            }

            Socket graphiteSocket = null;
            OutputStream stream = null;
            try {
                graphiteSocket = new Socket(graphiteHost, graphitePort);
                stream = graphiteSocket.getOutputStream();
                stream.write(lines.toString().getBytes(Charset.forName("UTF-8")));
            } catch (IOException ex) {
                LOG.error("Failed to write the stats", ex);
            } finally {
                if (null != graphiteSocket && !graphiteSocket.isClosed()) {
                    try {
                        graphiteSocket.close();
                    } catch (IOException ex) {
                        LOG.warn("failure in closing the connection to graphite server", ex);
                    }
                }
                if (null != stream) {
                    try {
                        stream.close();
                    } catch (IOException ex) {
                        LOG.warn("failure in closing the input stream", ex);
                    }
                }
            }
        }
    }
}

From source file:org.eclipse.ecf.internal.provider.filetransfer.httpclient4.ECFHttpClientSecureProtocolSocketFactory.java

public boolean isSecure(final Socket sock) throws IllegalArgumentException {
    if (sock == null) {
        throw new IllegalArgumentException("Socket must not be null"); //$NON-NLS-1$
    }// ww  w.  j  av a  2s .c  o m

    if (sock instanceof CloseMonitoringSocket) {
        return ((CloseMonitoringSocket) sock).isSecure();
    }

    if (!(sock instanceof SSLSocket)) {
        throw new IllegalArgumentException("Socket not created by this factory"); //$NON-NLS-1$
    }

    if (sock.isClosed()) {
        throw new IllegalArgumentException("Socket is closed"); //$NON-NLS-1$
    }

    return true;
}