Skip to content

Instantly share code, notes, and snippets.

@dmlloyd
Last active August 29, 2015 14:15
Show Gist options
  • Save dmlloyd/2d43c7afd84f14d73e2e to your computer and use it in GitHub Desktop.
Save dmlloyd/2d43c7afd84f14d73e2e to your computer and use it in GitHub Desktop.
Asynchronous channel base interface
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.examples.example1;
import java.io.IOException;
import io.examples.BufferPool2;
/**
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
*/
public interface AsynchronousChannel3 extends CloseableChannel3 {
void checkResult() throws IOException;
/**
* Get the worker for this channel.
*
* @return the worker
*/
default XnioWorker getWorker() {
return getIoThread().getWorker();
}
XnioIoThread getIoThread();
BufferPool2 getBufferPool();
/**
* Get the number of times this channel has been enqueued in a row. Callbacks may choose to
* {@link #yield(IoCallback2, Object)} once this number gets high enough, in order to prevent starvation
* of other workers.
*
* @return the number of times this channel has been enqueued
*/
int getEnqueuedCount();
/**
* Yield to the next enqueued channel callback.
*
* @param callback the callback to call to resume work
*/
default void yield(IoCallback2<?> callback) {
yield(callback, null);
}
/**
* Yield to the next enqueued channel callback.
*
* @param callback the callback to call to resume work
* @param attachment the attachment to pass to the callback
* @param <T> the attachment type
*/
<T> void yield(IoCallback2<T> callback, T attachment);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment