本文整理汇总了Java中org.apache.mina.core.RuntimeIoException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java RuntimeIoException.printStackTrace方法的具体用法?Java RuntimeIoException.printStackTrace怎么用?Java RuntimeIoException.printStackTrace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.core.RuntimeIoException
的用法示例。
在下文中一共展示了RuntimeIoException.printStackTrace方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.mina.core.RuntimeIoException; //导入方法依赖的package包/类
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();
}
示例2: connect
import org.apache.mina.core.RuntimeIoException; //导入方法依赖的package包/类
public synchronized void connect() throws InterruptedException {
for (;;) {
try {
ConnectFuture future = connector.connect(addr);
future.awaitUninterruptibly();
session = future.getSession();
return;
} catch (RuntimeIoException e) {
System.err.println("Failed to connect.");
e.printStackTrace();
Thread.sleep(5000);
}
}
}
示例3: Client
import org.apache.mina.core.RuntimeIoException; //导入方法依赖的package包/类
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();
}
}
}
示例4: main
import org.apache.mina.core.RuntimeIoException; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable
{
IoBuffer.setUseDirectBuffer(false);
IoBuffer.setAllocator(new SimpleBufferAllocator());
SocketConnector connector =
new NioSocketConnector(Runtime.getRuntime().availableProcessors() + 1);
// Configure the service.
connector.setConnectTimeoutMillis(CONNECT_TIMEOUT);
connector.getFilterChain().addLast("threadPool", new ExecutorFilter(Executors.newFixedThreadPool(MAX_THREADS)));
connector.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
connector.getFilterChain().addLast("logger", new LoggingFilter());
SMTPSessionHandler handler = new SMTPSessionHandler("localhost");
connector.setHandler(handler);
while (true)
{
try
{
for (int i = 0; i < 10; i++)
connector.connect(new InetSocketAddress(HOSTNAME, PORT));
Thread.sleep(100);
}
catch (RuntimeIoException e)
{
System.err.println("Failed to connect.");
e.printStackTrace();
Thread.sleep(1000);
}
}
}
示例5: main
import org.apache.mina.core.RuntimeIoException; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
init(args);
NioSocketConnector connector = new NioSocketConnector();
// Configure the service.
connector.setConnectTimeoutMillis(CONNECT_TIMEOUT);
if (USE_CUSTOM_CODEC) {
connector.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new SumUpProtocolCodecFactory(false)));
} else {
connector.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
}
int[] values = new int[]{};
connector.getFilterChain().addLast("logger", new LoggingFilter());
connector.setHandler(new ClientSessionHandler(values));
long time = System.currentTimeMillis();
IoSession session;
for (; ; ) {
try {
System.out.println(host + " " + port + " " + fileTest);
ConnectFuture future = connector.connect(new InetSocketAddress(host, port));
future.awaitUninterruptibly();
session = future.getSession();
File file = new File(fileTest);
FileInputStream is = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
int data = br.read();
int count = 0;
IoBuffer ib = IoBuffer.allocate(274);
ib.setAutoExpand(true);
boolean flagcount = false;
while(data != -1){
data = br.read();
ib.put((byte)data);
if (flagcount){count++;}
if (data==13){
count=1;
flagcount = true;
LOGGER.debug(ib.toString());
}
if (count == 4) {
ib.flip();
session.write(ib);
ib = IoBuffer.allocate(274);
ib.setAutoExpand(true);
flagcount = false;
count = 0;
//Thread.sleep(500);
}
}
break;
} catch (RuntimeIoException e) {
LOGGER.error("Failed to connect.");
e.printStackTrace();
Thread.sleep(5000);
}
}
time = System.currentTimeMillis() - time;
LOGGER.info("Time " + time);
// wait until the summation is done
session.getCloseFuture().awaitUninterruptibly();
connector.dispose();
}