Search in sources :

Example 1 with StreamPump

use of com.predic8.membrane.core.transport.http.StreamPump in project service-proxy by membrane.

the class AdminPageBuilder method createStreamPumpsTable.

protected void createStreamPumpsTable() throws UnsupportedEncodingException {
    table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display", "id", "stream-pumps-table");
    thead();
    tr();
    createThs("Name", "Service Proxy", "Creation Time", "Active Time", "Transferred Bytes");
    end();
    end();
    tbody();
    for (StreamPump p : router.getStatistics().getStreamPumpStats().getStreamPumps()) {
        tr().style("text-align: right;");
        td().style("text-align:left;").text(p.getName()).end();
        createTds(p.getServiceProxyName(), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(p.getCreationTime()), // TODO: Pretty Print with library
        (System.currentTimeMillis() - p.getCreationTime()) / 1000 + " seconds", "" + p.getTransferredBytes());
        end();
    }
    end();
    end();
}
Also used : StreamPump(com.predic8.membrane.core.transport.http.StreamPump) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with StreamPump

use of com.predic8.membrane.core.transport.http.StreamPump in project service-proxy by membrane.

the class HttpClient method setupConnectionForwarding.

public static void setupConnectionForwarding(Exchange exc, final Connection con, final String protocol, StreamPump.StreamPumpStats streamPumpStats) throws SocketException {
    final HttpServerHandler hsr = (HttpServerHandler) exc.getHandler();
    String source = hsr.getSourceSocket().getRemoteSocketAddress().toString();
    String dest = con.toString();
    final StreamPump a;
    final StreamPump b;
    if ("WebSocket".equals(protocol)) {
        WebSocketStreamPump aTemp = new WebSocketStreamPump(hsr.getSrcIn(), con.out, streamPumpStats, protocol + " " + source + " -> " + dest, exc.getRule(), true, exc);
        WebSocketStreamPump bTemp = new WebSocketStreamPump(con.in, hsr.getSrcOut(), streamPumpStats, protocol + " " + source + " <- " + dest, exc.getRule(), false, null);
        aTemp.init(bTemp);
        bTemp.init(aTemp);
        a = aTemp;
        b = bTemp;
    } else {
        a = new StreamPump(hsr.getSrcIn(), con.out, streamPumpStats, protocol + " " + source + " -> " + dest, exc.getRule());
        b = new StreamPump(con.in, hsr.getSrcOut(), streamPumpStats, protocol + " " + source + " <- " + dest, exc.getRule());
    }
    hsr.getSourceSocket().setSoTimeout(0);
    exc.addExchangeViewerListener(new AbstractExchangeViewerListener() {

        @Override
        public void setExchangeFinished() {
            String threadName = Thread.currentThread().getName();
            new Thread(b, threadName + " " + protocol + " Backward Thread").start();
            try {
                Thread.currentThread().setName(threadName + " " + protocol + " Onward Thread");
                a.run();
            } finally {
                try {
                    con.close();
                } catch (IOException e) {
                    log.debug("", e);
                }
            }
        }
    });
}
Also used : IOException(java.io.IOException) AbstractExchangeViewerListener(com.predic8.membrane.core.model.AbstractExchangeViewerListener)

Aggregations

AbstractExchangeViewerListener (com.predic8.membrane.core.model.AbstractExchangeViewerListener)1 StreamPump (com.predic8.membrane.core.transport.http.StreamPump)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1