org.apache.mina.core.RuntimeIoException Java Examples

The following examples show how to use org.apache.mina.core.RuntimeIoException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HelloTcpClient.java    From mina-examples with MIT License 6 votes vote down vote up
public static void main(String[] args) {
	NioSocketConnector connector = new NioSocketConnector(); //TCP Connector
	connector.getFilterChain().addLast("logging", new LoggingFilter());
	connector.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
    connector.getFilterChain().addLast("mdc", new MdcInjectionFilter());
	connector.setHandler(new HelloClientHandler());
    IoSession session;

    for (;;) {
        try {
            ConnectFuture future = connector.connect(new InetSocketAddress(HOSTNAME, PORT));
            future.awaitUninterruptibly();
            session = future.getSession();
            break;
        } catch (RuntimeIoException e) {
            System.err.println("Failed to connect.");
            e.printStackTrace();
        }
    }
    session.getCloseFuture().awaitUninterruptibly();
    connector.dispose();
}
 
Example #2
Source File: DefaultReadFuture.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public Object getMessage() {
    if (isDone()) {
        Object v = getValue();
        if (v == CLOSED) {
            return null;
        }

        if (v instanceof ExceptionHolder) {
            v = ((ExceptionHolder) v).exception;
            if (v instanceof RuntimeException) {
                throw (RuntimeException) v;
            }
            if (v instanceof Error) {
                throw (Error) v;
            }
            if (v instanceof IOException || v instanceof Exception) {
                throw new RuntimeIoException((Exception) v);
            }
        }

        return v;
    }

    return null;
}
 
Example #3
Source File: TCPTestClient.java    From streamsx.topology with Apache License 2.0 6 votes vote down vote up
public synchronized void connect() throws InterruptedException {
    for (int i = 0; i < 5; i++) {
        try {
            TRACE.info("Attempting to connect to test collector: " + addr);
            ConnectFuture future = connector.connect(addr);
            future.awaitUninterruptibly();
            session = future.getSession();
            TRACE.info("Connected to test collector: " + addr);
            return;
        } catch (RuntimeIoException e) {
            e.printStackTrace(System.err);
            if (i < 4) {
                TRACE.warning("Failed to connect to test collector - retrying: " + addr);
                Thread.sleep(1000);
            } else {
                TRACE.severe("Failed to connect to test collector: " + addr);
                throw e;
            }
        }
    }
    
}
 
Example #4
Source File: DefaultConnectFuture.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IoSession getSession() {
    Object v = getValue();
    if (v instanceof RuntimeException) {
        throw (RuntimeException) v;
    } else if (v instanceof Error) {
        throw (Error) v;
    } else if (v instanceof Throwable) {
        throw (RuntimeIoException) new RuntimeIoException("Failed to get the session.").initCause((Throwable) v);
    } else if (v instanceof IoSession) {
        return (IoSession) v;
    } else {
        return null;
    }
}
 
Example #5
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void setReceiveBufferSize(int size) {
    try {
        getSocket().setReceiveBufferSize(size);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #6
Source File: NioDatagramSessionConfig.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * @throws RuntimeIoException If the socket is closed or if we get an
 * {@link SocketException} 
 */
public void setTrafficClass(int trafficClass) {
    try {
        channel.socket().setTrafficClass(trafficClass);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #7
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isKeepAlive() {
    try {
        return getSocket().getKeepAlive();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #8
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void setKeepAlive(boolean on) {
    try {
        getSocket().setKeepAlive(on);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #9
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isOobInline() {
    try {
        return getSocket().getOOBInline();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #10
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void setOobInline(boolean on) {
    try {
        getSocket().setOOBInline(on);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #11
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isReuseAddress() {
    try {
        return getSocket().getReuseAddress();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #12
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void setReuseAddress(boolean on) {
    try {
        getSocket().setReuseAddress(on);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #13
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public int getSoLinger() {
    try {
        return getSocket().getSoLinger();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #14
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void setSoLinger(int linger) {
    try {
        if (linger < 0) {
            getSocket().setSoLinger(false, 0);
        } else {
            getSocket().setSoLinger(true, linger);
        }
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #15
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isTcpNoDelay() {
    if (!isConnected()) {
        return false;
    }

    try {
        return getSocket().getTcpNoDelay();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #16
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void setTcpNoDelay(boolean on) {
    try {
        getSocket().setTcpNoDelay(on);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #17
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int getTrafficClass() {
    try {
        return getSocket().getTrafficClass();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #18
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void setTrafficClass(int tc) {
    try {
        getSocket().setTrafficClass(tc);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #19
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public int getSendBufferSize() {
    try {
        return getSocket().getSendBufferSize();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #20
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void setSendBufferSize(int size) {
    try {
        getSocket().setSendBufferSize(size);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #21
Source File: NioSocketSession.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public int getReceiveBufferSize() {
    try {
        return getSocket().getReceiveBufferSize();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #22
Source File: NioDatagramSessionConfig.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tells if SO_REUSEADDR is enabled.
 * 
 * @return <code>true</code> if SO_REUSEADDR is enabled
 * @throws RuntimeIoException If the socket is closed or if we get an
 * {@link SocketException} 
 */
public boolean isReuseAddress() {
    try {
        return channel.socket().getReuseAddress();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #23
Source File: MulticastDatagramSessionConfig.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
/**
 * Tells if SO_BROADCAST is enabled.
 * 
 * @return <code>true</code> if SO_BROADCAST is enabled
 * @throws RuntimeIoException If the socket is closed or if we get an
 * {@link SocketException} 
 */
public boolean isBroadcast() {
    try {
        return socket.getBroadcast();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #24
Source File: MulticastDatagramSessionConfig.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public void setBroadcast(boolean broadcast) {
    try {
        socket.setBroadcast(broadcast);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #25
Source File: MulticastDatagramSessionConfig.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @throws RuntimeIoException If the socket is closed or if we get an
 * {@link SocketException} 
 */
public int getSendBufferSize() {
    try {
        return socket.getSendBufferSize();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #26
Source File: MulticastDatagramSessionConfig.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @throws RuntimeIoException If the socket is closed or if we get an
 * {@link SocketException} 
 */
public void setSendBufferSize(int sendBufferSize) {
    try {
        socket.setSendBufferSize(sendBufferSize);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #27
Source File: MulticastDatagramSessionConfig.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
/**
 * Tells if SO_REUSEADDR is enabled.
 * 
 * @return <code>true</code> if SO_REUSEADDR is enabled
 * @throws RuntimeIoException If the socket is closed or if we get an
 * {@link SocketException} 
 */
public boolean isReuseAddress() {
    try {
        return socket.getReuseAddress();
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #28
Source File: MulticastDatagramSessionConfig.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @throws RuntimeIoException If the socket is closed or if we get an
 * {@link SocketException} 
 */
public void setReuseAddress(boolean reuseAddress) {
    try {
        socket.setReuseAddress(reuseAddress);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}
 
Example #29
Source File: Client.java    From gameserver with Apache License 2.0 5 votes vote down vote up
public Client(ArrayList<Class> testCases, String host, int port, boolean longRunning) 
			throws Exception {
	
	// Set up
	this.longRunning = longRunning;
	this.testcaseClasses = testCases;
	this.testcases = new ArrayList(this.testcaseClasses.size());
	for ( int i=0; i<this.testcaseClasses.size(); i++ ) {
		this.testcases.add(this.testcaseClasses.get(i).newInstance());
		logger.info("testcase: " + this.testcaseClasses.get(i));
	}
	this.context = new EnumMap<ContextKey, Object>(ContextKey.class);
	
	connector = new NioSocketConnector();
	connector.getFilterChain().addLast("codec", 
			new ProtocolCodecFilter(new ProtobufEncoder(), new ProtobufDecoder()));
	connector.setHandler(this);
	
	// Make a new connection
   ConnectFuture connectFuture = connector.connect(new InetSocketAddress(host, port));
   // Wait until the connection is make successfully.
   connectFuture.awaitUninterruptibly(CONNECT_TIMEOUT);
   try {
       session = connectFuture.getSession();
       logger.info("client connected");
   }
   catch (RuntimeIoException e) {
   	e.printStackTrace();
   	if ( session != null ) {
   		session.close();
   	}
   }
}
 
Example #30
Source File: MulticastDatagramSessionConfig.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * @throws RuntimeIoException If the socket is closed or if we get an
 * {@link SocketException} 
 */
public void setTrafficClass(int trafficClass) {
    try {
        socket.setTrafficClass(trafficClass);
    } catch (SocketException e) {
        throw new RuntimeIoException(e);
    }
}