本文整理汇总了Java中org.xnio.ChannelListener类的典型用法代码示例。如果您正苦于以下问题:Java ChannelListener类的具体用法?Java ChannelListener怎么用?Java ChannelListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChannelListener类属于org.xnio包,在下文中一共展示了ChannelListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: on
import org.xnio.ChannelListener; //导入依赖的package包/类
@Override
public final void on(final Buffer result) {
//broadcast to anyone...
WebSocketChannel[] others = peers.toArray(new WebSocketChannel[peers.size()]);
Buffer notificationBuffer = new HeapBuffer();
notificationBuffer.write(WSConstants.NOTIFY_UPDATE);
notificationBuffer.write(Constants.BUFFER_SEP);
notificationBuffer.writeAll(result.data());
byte[] notificationMsg = notificationBuffer.data();
notificationBuffer.free();
for (int i = 0; i < others.length; i++) {
PeerInternalListener listener = (PeerInternalListener) ((ChannelListener.SimpleSetter) others[i].getReceiveSetter()).get();
//locally invalidate cache
listener.graph.remoteNotify(result);
//notify to connected peer
send_flat_resp(notificationMsg, others[i]);
}
}
示例2: connect
import org.xnio.ChannelListener; //导入依赖的package包/类
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final Pool<ByteBuffer> bufferPool, final OptionMap options) {
ChannelListener<StreamConnection> openListener = new ChannelListener<StreamConnection>() {
@Override
public void handleEvent(StreamConnection connection) {
handleConnected(connection, listener, uri, ssl, bufferPool, options);
}
};
IoFuture.Notifier<StreamConnection, Object> notifier = new IoFuture.Notifier<StreamConnection, Object>() {
@Override
public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
listener.failed(ioFuture.getException());
}
}
};
if(bindAddress == null) {
worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, options).addNotifier(notifier, null);
} else {
worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, null, options).addNotifier(notifier, null);
}
}
示例3: HttpClientConnection
import org.xnio.ChannelListener; //导入依赖的package包/类
HttpClientConnection(final StreamConnection connection, final OptionMap options, final Pool<ByteBuffer> bufferPool) {
this.options = options;
this.connection = connection;
this.pushBackStreamSourceConduit = new PushBackStreamSourceConduit(connection.getSourceChannel().getConduit());
this.connection.getSourceChannel().setConduit(pushBackStreamSourceConduit);
this.bufferPool = bufferPool;
this.originalSinkConduit = connection.getSinkChannel().getConduit();
connection.getCloseSetter().set(new ChannelListener<StreamConnection>() {
public void handleEvent(StreamConnection channel) {
HttpClientConnection.this.state |= CLOSED;
ChannelListeners.invokeChannelListener(HttpClientConnection.this, closeSetter.get());
}
});
}
示例4: handleConnected
import org.xnio.ChannelListener; //导入依赖的package包/类
private void handleConnected(final StreamConnection connection, final ClientCallback<ClientConnection> listener, final Pool<ByteBuffer> bufferPool, final OptionMap options) {
if (options.get(UndertowOptions.ENABLE_SPDY, false) && connection instanceof SslConnection && SpdyClientProvider.isEnabled()) {
try {
SpdyClientProvider.handlePotentialSpdyConnection(connection, listener, bufferPool, options, new ChannelListener<SslConnection>() {
@Override
public void handleEvent(SslConnection channel) {
listener.completed(new HttpClientConnection(connection, options, bufferPool));
}
});
} catch (Exception e) {
listener.failed(new IOException(e));
}
} else {
listener.completed(new HttpClientConnection(connection, options, bufferPool));
}
}
示例5: handleEvent
import org.xnio.ChannelListener; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void handleEvent(final StreamSourceChannel channel) {
final R receiver = AbstractFramedChannel.this.receiver;
if ((isLastFrameReceived() || receivesSuspended) && receiver == null) {
channel.suspendReads();
return;
} else {
final ChannelListener listener = receiveSetter.get();
if (listener != null) {
WebSocketLogger.REQUEST_LOGGER.debugf("Invoking receive listener", receiver);
ChannelListeners.invokeChannelListener(AbstractFramedChannel.this, listener);
} else {
channel.suspendReads();
}
}
if (readData != null && channel.isOpen()) {
ChannelListeners.invokeChannelListener(channel.getIoThread(), channel, this);
}
}
示例6: close
import org.xnio.ChannelListener; //导入依赖的package包/类
@Override
public void close() throws IOException {
if(anyAreSet(state, STATE_CLOSED)) {
return;
}
state |= STATE_CLOSED;
if (allAreClear(state, STATE_DONE | STATE_LAST_FRAME)) {
state |= STATE_STREAM_BROKEN;
getFramedChannel().notifyClosed(this);
channelForciblyClosed();
}
if (data != null) {
data.free();
data = null;
}
while (!pendingFrameData.isEmpty()) {
pendingFrameData.poll().frameData.free();
}
ChannelListeners.invokeChannelListener(this, (ChannelListener<? super AbstractFramedStreamSourceChannel<C, R, S>>) closeSetter.get());
}
示例7: removeProtocol
import org.xnio.ChannelListener; //导入依赖的package包/类
/**
* Remove a protocol from this handler.
*
* @param productString the product string to match
* @param openListener The open listener
*/
public synchronized void removeProtocol(String productString, ChannelListener<? super StreamConnection> openListener) {
List<Holder> holders = handlers.get(productString);
if (holders == null) {
return;
}
Iterator<Holder> it = holders.iterator();
while (it.hasNext()) {
Holder holder = it.next();
if (holder.listener == openListener) {
it.remove();
break;
}
}
if (holders.isEmpty()) {
handlers.remove(productString);
}
}
示例8: WebSocketChannel
import org.xnio.ChannelListener; //导入依赖的package包/类
/**
* Create a new {@link WebSocketChannel}
* 8
*
* @param connectedStreamChannel The {@link org.xnio.channels.ConnectedStreamChannel} over which the WebSocket Frames should get send and received.
* Be aware that it already must be "upgraded".
* @param bufferPool The {@link org.xnio.Pool} which will be used to acquire {@link java.nio.ByteBuffer}'s from.
* @param version The {@link WebSocketVersion} of the {@link WebSocketChannel}
* @param wsUrl The url for which the channel was created.
* @param client
* @param peerConnections The concurrent set that is used to track open connections associtated with an endpoint
*/
protected WebSocketChannel(final StreamConnection connectedStreamChannel, Pool<ByteBuffer> bufferPool, WebSocketVersion version, String wsUrl, String subProtocol, final boolean client, boolean extensionsSupported, Set<WebSocketChannel> peerConnections) {
super(connectedStreamChannel, bufferPool, new WebSocketFramePriority(), null);
this.client = client;
this.version = version;
this.wsUrl = wsUrl;
this.extensionsSupported = extensionsSupported;
this.subProtocol = subProtocol;
this.peerConnections = peerConnections;
addCloseTask(new ChannelListener<WebSocketChannel>() {
@Override
public void handleEvent(WebSocketChannel channel) {
WebSocketChannel.this.peerConnections.remove(WebSocketChannel.this);
}
});
}
示例9: writeDone
import org.xnio.ChannelListener; //导入依赖的package包/类
protected void writeDone(final StreamSinkChannel channel) {
try {
channel.shutdownWrites();
if (!channel.flush()) {
channel.getWriteSetter().set(ChannelListeners.flushingChannelListener(new ChannelListener<StreamSinkChannel>() {
@Override
public void handleEvent(StreamSinkChannel o) {
IoUtils.safeClose(channel);
}
}, ChannelListeners.closingChannelExceptionHandler()));
channel.resumeWrites();
}
} catch (IOException e) {
handleError(channel, e);
}
}
示例10: initWriteListener
import org.xnio.ChannelListener; //导入依赖的package包/类
private void initWriteListener() {
writeListener = new ChannelListener<StreamSinkChannel>() {
@Override
public void handleEvent(final StreamSinkChannel streamSinkChannel) {
try {
long toWrite = Buffers.remaining(buffer);
long written = 0;
while (written < toWrite) {
long res = streamSinkChannel.write(buffer, 0, buffer.length);
written += res;
if (res == 0) {
return;
}
}
streamSinkChannel.suspendWrites();
invokeOnComplete();
} catch (IOException e) {
streamSinkChannel.suspendWrites();
invokeOnException(callback, e);
}
}
};
}
示例11: completed
import org.xnio.ChannelListener; //导入依赖的package包/类
@Override
public void completed(final ClientConnection connection) {
final ServerConnection serverConnection = exchange.getConnection();
//we attach to the connection so it can be re-used
serverConnection.putAttachment(clientAttachmentKey, connection);
serverConnection.addCloseListener(serverConnection1 -> IoUtils.safeClose(connection));
connection.getCloseSetter().set((ChannelListener<Channel>) channel -> serverConnection.removeAttachment(clientAttachmentKey));
exchange.setRelativePath("/");
Realm realm = realmCache.matches(exchange.getRequestPath());
Application application = realmCache.getApplication(realm);
String path = exchange.getRequestURI();
if (path.startsWith(application.getVirtualPath())) {
String passTo = calculatePathTo(path, application);
exchange.setRequestPath(passTo);
exchange.setRequestURI(passTo);
}
callback.completed(exchange, new ProxyConnection(connection, "/"));
}
示例12: registerWebSocketChannelListener
import org.xnio.ChannelListener; //导入依赖的package包/类
private void registerWebSocketChannelListener(WebSocketChannel webSocketChannel) {
ChannelListener<WebSocketChannel> listener = new AbstractReceiveListener() {
@Override
protected void onFullBinaryMessage(WebSocketChannel channel, BufferedBinaryMessage message) throws IOException {
log.log(Level.FINE, "Server received full binary message");
Pooled<ByteBuffer[]> pulledData = message.getData();
try {
ByteBuffer[] resource = pulledData.getResource();
ByteBuffer byteBuffer = WebSockets.mergeBuffers(resource);
String msg = new String(byteBuffer.array());
log.log(Level.FINE, "Sending message to decoder: "+ msg);
writeToDecoder(msg);
}
finally {
pulledData.discard();
}
}
};
webSocketChannel.getReceiveSetter().set(listener);
}
示例13: onConnect
import org.xnio.ChannelListener; //导入依赖的package包/类
@Override
public void onConnect(WebSocketHttpExchange exchange, WebSocketChannel channel) {
if (this.hasAuthentication) {
String header = null;
if (exchange.getRequestHeader(Header.COOKIE.toString()) != null) {
header = exchange.getRequestHeader(Header.COOKIE.toString());
}
if (this.requestHelper.hasValidAuthentication(header)) {
channel.getReceiveSetter().set((ChannelListener<? super WebSocketChannel>) Application.getInstance(this.controllerClass));
channel.resumeReceives();
channel.addCloseTask(Application.getInstance(WebSocketCloseListener.class));
Application.getInstance(WebSocketService.class).addChannel(channel);
} else {
IOUtils.closeQuietly(channel);
}
} else {
channel.getReceiveSetter().set((ChannelListener<? super WebSocketChannel>) Application.getInstance(this.controllerClass));
channel.resumeReceives();
channel.addCloseTask(Application.getInstance(WebSocketCloseListener.class));
Application.getInstance(WebSocketService.class).addChannel(channel);
}
}
示例14: registerWebSocketChannelListener
import org.xnio.ChannelListener; //导入依赖的package包/类
private void registerWebSocketChannelListener(WebSocketChannel webSocketChannel) {
ChannelListener<WebSocketChannel> listener = new AbstractReceiveListener() {
@Override
protected void onFullBinaryMessage(WebSocketChannel channel, BufferedBinaryMessage message) throws IOException {
log.trace("Server received full binary message");
Pooled<ByteBuffer[]> pulledData = message.getData();
try {
ByteBuffer[] resource = pulledData.getResource();
ByteBuffer byteBuffer = WebSockets.mergeBuffers(resource);
String msg = new String(byteBuffer.array());
log.trace("Sending message to decoder: {}", msg);
writeToDecoder(msg);
} finally {
pulledData.discard();
}
}
};
webSocketChannel.getReceiveSetter().set(listener);
}
示例15: start
import org.xnio.ChannelListener; //导入依赖的package包/类
public void start() {
try {
OptionMap.Builder serverOptionsBuilder = OptionMap.builder()
.set(Options.TCP_NODELAY, true)
.set(Options.REUSE_ADDRESSES, true);
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
if (httpAddress != null) {
normalServer = worker.createStreamConnectionServer(httpAddress, acceptListener, serverOptionsBuilder.getMap());
normalServer.resumeAccepts();
}
if (secureAddress != null) {
if (sslClientAuthMode != null) {
serverOptionsBuilder.set(SSL_CLIENT_AUTH_MODE, sslClientAuthMode);
}
OptionMap secureOptions = serverOptionsBuilder.getMap();
XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), secureOptions, sslContext);
secureServer = xnioSsl.createSslConnectionServer(worker, secureAddress, acceptListener, secureOptions);
secureServer.resumeAccepts();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}