当前位置: 首页>>代码示例>>Java>>正文


Java CompletedCallback类代码示例

本文整理汇总了Java中com.koushikdutta.async.callback.CompletedCallback的典型用法代码示例。如果您正苦于以下问题:Java CompletedCallback类的具体用法?Java CompletedCallback怎么用?Java CompletedCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompletedCallback类属于com.koushikdutta.async.callback包,在下文中一共展示了CompletedCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAccepted

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
@Override
public void onAccepted(AsyncSocket socket) {
    // this example service shows only a single server <-> client communication
    if (asyncClient != null) {
        asyncClient.close();
    }
    asyncClient = (AsyncNetworkSocket) socket;
    asyncClient.setDataCallback(new DataCallback() {
        @Override
        public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
            Timber.i("Data received: %s", bb.readString());
        }
    });
    asyncClient.setClosedCallback(new CompletedCallback() {
        @Override
        public void onCompleted(Exception ex) {
            asyncClient = null;
            Timber.i("Client socket closed");
        }
    });
    Timber.i("Client socket connected");
}
 
开发者ID:maks,项目名称:UartBridge,代码行数:23,代码来源:SocketServer.java

示例2: handshake

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
public static void handshake(AsyncSocket socket,
                             String host, int port,
                             SSLEngine sslEngine,
                             TrustManager[] trustManagers, HostnameVerifier verifier, boolean clientMode,
                             final HandshakeCallback callback) {
    AsyncSSLSocketWrapper wrapper = new AsyncSSLSocketWrapper(socket, host, port, sslEngine, trustManagers, verifier, clientMode);
    wrapper.handshakeCallback = callback;
    socket.setClosedCallback(new CompletedCallback() {
        @Override
        public void onCompleted(Exception ex) {
            if (ex != null)
                callback.onHandshakeCompleted(ex, null);
            else
                callback.onHandshakeCompleted(new SSLException("socket closed during handshake"), null);
        }
    });
    try {
        wrapper.engine.beginHandshake();
        wrapper.handleHandshakeStatus(wrapper.engine.getHandshakeStatus());
    } catch (SSLException e) {
        wrapper.report(e);
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:24,代码来源:AsyncSSLSocketWrapper.java

示例3: recycleSocket

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
private void recycleSocket(final AsyncSocket socket, AsyncHttpRequest request) {
    if (socket == null)
        return;
    Uri uri = request.getUri();
    int port = getSchemePort(uri);
    final String lookup = computeLookup(uri, port, request.getProxyHost(), request.getProxyPort());
    final ArrayDeque<IdleSocketHolder> sockets;
    final IdleSocketHolder idleSocketHolder = new IdleSocketHolder(socket);
    synchronized (AsyncSocketMiddleware.this) {
        ConnectionInfo info = getOrCreateConnectionInfo(lookup);
        sockets = info.sockets;
        sockets.push(idleSocketHolder);
    }
    socket.setClosedCallback(new CompletedCallback() {
        @Override
        public void onCompleted(Exception ex) {
            synchronized (AsyncSocketMiddleware.this) {
                sockets.remove(idleSocketHolder);
                maybeCleanupConnectionInfo(lookup);
            }
        }
    });
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:24,代码来源:AsyncSocketMiddleware.java

示例4: report

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
private void report(Exception e) {
    final HandshakeCallback hs = handshakeCallback;
    if (hs != null) {
        handshakeCallback = null;
        mSocket.setDataCallback(new DataCallback.NullDataCallback());
        mSocket.end();
        // handshake sets this callback. unset it.
        mSocket.setClosedCallback(null);
        mSocket.close();
        hs.onHandshakeCompleted(e, null);
        return;
    }

    CompletedCallback cb = getEndCallback();
    if (cb != null)
        cb.onCompleted(e);
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:18,代码来源:AsyncSSLSocketWrapper.java

示例5: setUp

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();

    httpServer = new AsyncHttpServer();
    httpServer.setErrorCallback(new CompletedCallback() {
        @Override
        public void onCompleted(Exception ex) {
            fail();
        }
    });
    httpServer.listen(AsyncServer.getDefault(), 5000);
    

    httpServer.websocket("/ws", new WebSocketRequestCallback() {
        @Override
        public void onConnected(final WebSocket webSocket, AsyncHttpServerRequest request) {
            webSocket.setStringCallback(new StringCallback() {
                @Override
                public void onStringAvailable(String s) {
                    webSocket.send(s);
                }
            });
        }
    });
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:27,代码来源:WebSocketTests.java

示例6: proxy

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
@Override
public void proxy(final AsyncHttpResponse remoteResponse) {
    code(remoteResponse.code());
    remoteResponse.headers().removeAll("Transfer-Encoding");
    remoteResponse.headers().removeAll("Content-Encoding");
    remoteResponse.headers().removeAll("Connection");
    getHeaders().addAll(remoteResponse.headers());
    // TODO: remove?
    remoteResponse.headers().set("Connection", "close");
    Util.pump(remoteResponse, this, new CompletedCallback() {
        @Override
        public void onCompleted(Exception ex) {
            remoteResponse.setEndCallback(new NullCompletedCallback());
            remoteResponse.setDataCallback(new DataCallback.NullDataCallback());
            end();
        }
    });
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:19,代码来源:AsyncHttpServerResponseImpl.java

示例7: wrap

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
private CompletedCallback wrap() {
    return new CompletedCallback() {
        boolean mThisCompleted;
        @Override
        public void onCompleted(Exception ex) {
            // onCompleted may be called more than once... buggy code.
            // only accept the first (timeouts, etc)
            if (mThisCompleted)
                return;
            mThisCompleted = true;
            assert waiting;
            waiting = false;
            if (ex == null) {
                next();
                return;
            }
            reportCompleted(ex);
        }
    };
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:21,代码来源:Continuation.java

示例8: testContinuationFail

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
public void testContinuationFail() throws Exception {
    final Semaphore semaphore = new Semaphore(0);
    final Continuation c = new Continuation(new CompletedCallback() {
        @Override
        public void onCompleted(Exception ex) {
            assertNotNull(ex);
            semaphore.release();
        }
    });
    
    c.add(new ContinuationCallback() {
        @Override
        public void onContinue(Continuation continuation, CompletedCallback next) throws Exception {
            throw new Exception("fail");
        }
    });
    
    new Thread() {
        public void run() {
            c.start();
        };
    }.start();
    
    assertTrue(semaphore.tryAcquire(3000, TimeUnit.MILLISECONDS));
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:26,代码来源:FutureTests.java

示例9: idleSocket

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
private void idleSocket(final AsyncSocket socket) {
    // must listen for socket close, otherwise log will get spammed.
    socket.setEndCallback(new CompletedCallback() {
        @Override
        public void onCompleted(Exception ex) {
            socket.setClosedCallback(null);
            socket.close();
        }
    });
    socket.setWriteableCallback(null);
    // should not get any data after this point...
    // if so, eat it and disconnect.
    socket.setDataCallback(new DataCallback.NullDataCallback() {
        @Override
        public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
            super.onDataAvailable(emitter, bb);
            bb.recycle();
            socket.setClosedCallback(null);
            socket.close();
        }
    });
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:23,代码来源:AsyncSocketMiddleware.java

示例10: getBody

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
public static AsyncHttpRequestBody getBody(DataEmitter emitter, CompletedCallback reporter, Headers headers) {
    String contentType = headers.get("Content-Type");
    if (contentType != null) {
        String[] values = contentType.split(";");
        for (int i = 0; i < values.length; i++) {
            values[i] = values[i].trim();
        }
        for (String ct: values) {
            if (UrlEncodedFormBody.CONTENT_TYPE.equals(ct)) {
                return new UrlEncodedFormBody();
            }
            if (JSONObjectBody.CONTENT_TYPE.equals(ct)) {
                return new JSONObjectBody();
            }
            if (StringBody.CONTENT_TYPE.equals(ct)) {
                return new StringBody();
            }
            if (MultipartFormDataBody.CONTENT_TYPE.equals(ct)) {
                return new MultipartFormDataBody(values);
            }
        }
    }

    return null;
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:26,代码来源:HttpUtil.java

示例11: testContinuationArray

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
public void testContinuationArray() throws Exception {
    final ArrayList<Integer> results = new ArrayList<Integer>();
    final Semaphore semaphore = new Semaphore(0);
    final Continuation c = new Continuation(new CompletedCallback() {
        @Override
        public void onCompleted(Exception ex) {
            semaphore.release();
        }
    });
    
    for (int i = 0; i < 10; i++) {
        final int j = i;
        c.add(new ContinuationCallback() {
            @Override
            public void onContinue(Continuation continuation, CompletedCallback next) throws Exception {
                results.add(j);
                next.onCompleted(null);
            }
        });
    }
    
    new Thread() {
        public void run() {
            c.start();
        };
    }.start();
    
    assertTrue(semaphore.tryAcquire(3000, TimeUnit.MILLISECONDS));
    
    assertEquals(10, results.size());
    for (int i = 0; i < 10; i++) {
        assertEquals((int)results.get(i), i);
    }
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:35,代码来源:FutureTests.java

示例12: add

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
public Continuation add(final DependentFuture future) {
    future.setParent(this);
    add(new ContinuationCallback() {
        @Override
        public void onContinue(Continuation continuation, CompletedCallback next) throws Exception {
            future.get();
            next.onCompleted(null);
        }
    });
    return this;
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:12,代码来源:Continuation.java

示例13: writeAll

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
public static void writeAll(final DataSink sink, final ByteBufferList bb, final CompletedCallback callback) {
    WritableCallback wc;
    sink.setWriteableCallback(wc = new WritableCallback() {
        @Override
        public void onWriteable() {
            sink.write(bb);
            if (bb.remaining() == 0 && callback != null) {
                sink.setWriteableCallback(null);
                callback.onCompleted(null);
            }
        }
    });
    wc.onWriteable();
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:15,代码来源:Util.java

示例14: setClosedCallback

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
@Override
public void setClosedCallback(CompletedCallback handler) {
    if (mSink != null)
        mSink.setClosedCallback(handler);
    else
        closedCallback = handler;
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:8,代码来源:AsyncHttpServerResponseImpl.java

示例15: parse

import com.koushikdutta.async.callback.CompletedCallback; //导入依赖的package包/类
@Override
public void parse(DataEmitter emitter, final CompletedCallback completed) {
    new StringParser().parse(emitter).setCallback(new FutureCallback<String>() {
        @Override
        public void onCompleted(Exception e, String result) {
            string = result;
            completed.onCompleted(e);
        }
    });
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:11,代码来源:StringBody.java


注:本文中的com.koushikdutta.async.callback.CompletedCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。