@Override public void failed(Throwable exc, Integer id) { try { log.error("server accepts channel " + id + " error occurs", exc); } finally { listen(serverSocketChannel); } }} ); }
@Override public void failed(Throwable t, Integer sessionId) { log.error("session {} connect error", t, sessionId); }}); } catch (IOException e) {
public void close() { try { if (writer != null) writer.close(); } catch (Throwable t) { Config.LOG.error("java file builder close error", t); } }
public static byte[] str2Byte(String str, String charset) { byte[] ret = null; try { ret = str.getBytes(charset); } catch (UnsupportedEncodingException e) { Config.LOG.error("write text error", e); } return ret; }
public Config() { URL url = this.getClass().getResource(""); if ("jar".equals(url.getProtocol())) { String f = url.getPath(); try { this.classPath = new File(new URL(f.substring(0, f.indexOf("!/com/firefly"))).toURI()).getAbsolutePath(); } catch (Throwable t) { LOG.error("template config init error", t); } } }
public T get(long timeout) { T t = null; try { t = queue.poll(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { log.error("get synchronous obj error", e); } return t; }
public JavaFileBuilder(String path, String name, Config config) { this.name = name; File file = new File(path, name); try { if (!file.exists()) file.createNewFile(); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), config.getCharset())); this.config = config; } catch (Throwable t) { Config.LOG.error("java file builder error", t); } }
@Override public SSLContext getSSLContext() { try { return getSSLContextWithManager(null, null, null); } catch (Throwable e) { log.error("get SSL context error", e); return null; } }
private Object getObjectProperty(Object current, String propertyName) { Object ret = null; try { ret = ReflectUtils.get(current, propertyName); } catch (Throwable e) { Config.LOG.error("get property error", e); } return ret; }
@Override public void exceptionCaught(Session session, Throwable t) throws Throwable { log.error("client session error", t); session.closeNow(); }
@Override public SSLContext getSSLContext() { try { return getSSLContext(new ByteArrayInputStream(DEFAULT_CREDENTIAL), "ptmima1234", "ptmima4321"); } catch (Throwable e) { log.error("get SSL context error", e); return null; } }
@Override public void shutdownInput() { try { socketChannel.shutdownInput(); } catch (ClosedChannelException e) { log.debug("the session {} is closed", e, sessionId); } catch (IOException e) { log.error("the session {} shutdown input error", e, sessionId); } }
@Override public void executeExceptionTask(Session session, Throwable t) { try { config.getHandler().exceptionCaught(session, t); } catch (Throwable t0) { log.error("handler exception", t0); } }
@Override public void readBuffer(ByteBuffer buf, CountingCallback countingCallback, long count) { log.debug("write file, count: {} , lenth: {}", count, len); try { write(buf, countingCallback); } catch (Throwable e) { log.error("ssl session writing error", e); } }
@Override public void shutdownOutput() { try { socketChannel.shutdownOutput(); } catch (ClosedChannelException e) { log.debug("the session {} is closed", e, sessionId); } catch (IOException e) { log.error("the session {} shutdown output error", e, sessionId); } }
private AsynchronousServerSocketChannel bind(String host, int port) { AsynchronousServerSocketChannel serverSocketChannel = null; try { serverSocketChannel = AsynchronousServerSocketChannel.open(group); serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); serverSocketChannel.bind(new InetSocketAddress(host, port), BACKLOG); } catch (Exception e) { log.error("ServerSocket bind error", e); } return serverSocketChannel; }
public ArrayCollection(Object array) { obj = array; try { arrayProxy = ReflectUtils.getArrayProxy(array.getClass()); size = arrayProxy.size(array); } catch (Throwable e) { Config.LOG.error("get array proxy error", e); } iterator = new ArrayInterator(); }
@Override public void write(FileRegion file, Callback callback) { try (FileRegion fileRegion = file) { fileRegion.transferTo(callback, new FileBufferReaderHandler(fileRegion.getLength())); } catch (Throwable t) { log.error("transfer file error", t); } }
private void writingFailedCallback(Callback callback, Throwable t) { if (t instanceof InterruptedByTimeoutException) { if (log.isDebugEnabled()) { log.debug("the session {} writing data is timeout.", getSessionId()); } } else { log.error("the session {} writes data is failed", t, getSessionId()); } closeNow(); callback.failed(t); }