corda/classpath/java/nio/channels/SelectableChannel.java

39 lines
1.0 KiB
Java
Raw Normal View History

/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.nio.channels;
import java.io.IOException;
import java.nio.ByteBuffer;
public abstract class SelectableChannel implements Channel {
private SelectionKey key;
public abstract int read(ByteBuffer b) throws Exception;
public abstract int write(ByteBuffer b) throws Exception;
public abstract boolean isOpen();
public SelectionKey register(Selector selector, int interestOps,
Object attachment)
{
SelectionKey key = new SelectionKey
(this, selector, interestOps, attachment);
selector.add(key);
return key;
}
public void close() throws IOException {
if (key != null) {
key.selector().remove(key);
key = null;
}
}
}