You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/10/23 15:24:35 UTC
svn commit: r587500 - in
/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common:
java/nio/channels/spi/ org/apache/harmony/nio/internal/
Author: tellison
Date: Tue Oct 23 06:24:34 2007
New Revision: 587500
URL: http://svn.apache.org/viewvc?rev=587500&view=rev
Log:
Code tidy-up.
Modified:
harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/spi/AbstractInterruptibleChannel.java
harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/MappedByteBufferFactory.java
harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/spi/AbstractInterruptibleChannel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/spi/AbstractInterruptibleChannel.java?rev=587500&r1=587499&r2=587500&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/spi/AbstractInterruptibleChannel.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/spi/AbstractInterruptibleChannel.java Tue Oct 23 06:24:34 2007
@@ -24,6 +24,7 @@
import java.nio.channels.ClosedByInterruptException;
import java.nio.channels.InterruptibleChannel;
import java.security.AccessController;
+import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
/**
@@ -35,8 +36,7 @@
* the end method shows whether there has been any change to the java
* environment that is visible to the API user.
* </p>
- *
- */
+*/
public abstract class AbstractInterruptibleChannel implements Channel,
InterruptibleChannel {
@@ -54,7 +54,7 @@
}
});
setInterruptAction.setAccessible(true);
- } catch (Exception e) {
+ } catch (PrivilegedActionException e) {
// FIXME: be accommodate before VM actually provides
// setInterruptAction method
// throw new Error(e);
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/MappedByteBufferFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/MappedByteBufferFactory.java?rev=587500&r1=587499&r2=587500&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/MappedByteBufferFactory.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/MappedByteBufferFactory.java Tue Oct 23 06:24:34 2007
@@ -26,35 +26,37 @@
class MappedByteBufferFactory {
- static final Constructor constructor;
+ static final Constructor<?> constructor;
- static {
- constructor = AccessController
- .doPrivileged(new PrivilegedAction<Constructor>() {
- public Constructor run() {
- try {
- Class wrapperClazz = ClassLoader
- .getSystemClassLoader().loadClass(
- "java.nio.MappedByteBufferAdapter"); //$NON-NLS-1$
- Constructor result = wrapperClazz
- .getConstructor(new Class[] {
- PlatformAddress.class, int.class,
- int.class, int.class });
- result.setAccessible(true);
- return result;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- });
- }
+ static {
+ constructor = AccessController
+ .doPrivileged(new PrivilegedAction<Constructor<?>>() {
+ public Constructor<?> run() {
+ try {
+ Class<?> wrapperClazz = ClassLoader
+ .getSystemClassLoader().loadClass(
+ "java.nio.MappedByteBufferAdapter"); //$NON-NLS-1$
+ Constructor<?> result = wrapperClazz
+ .getConstructor(new Class[] {
+ PlatformAddress.class, int.class,
+ int.class, int.class });
+ result.setAccessible(true);
+ return result;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
- static MappedByteBuffer getBuffer(PlatformAddress addr, int mapmode,
- long size, int offset) throws Exception {
- // Spec points out explicitly that the size of map should be no greater than
- // Integer.MAX_VALUE, so long to int cast is safe here.
- return (MappedByteBuffer) constructor.newInstance(new Object[] { addr,
- new Integer((int) size), new Integer(offset),
- new Integer(mapmode) });
- }
+ static MappedByteBuffer getBuffer(PlatformAddress addr, int mapmode,
+ long size, int offset) throws Exception {
+ /*
+ * Spec points out explicitly that the size of map should be no greater
+ * than Integer.MAX_VALUE, so long to int cast is safe here.
+ */
+ return (MappedByteBuffer) constructor.newInstance(new Object[] { addr,
+ new Integer((int) size), new Integer(offset),
+ new Integer(mapmode) });
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java?rev=587500&r1=587499&r2=587500&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java Tue Oct 23 06:24:34 2007
@@ -58,11 +58,12 @@
private static final int SELECT_NOW = 0;
- // keysLock is used to brief synchronization when get selectionKeys snapshot
- // before selection
- final Object keysLock = new Object();
-
- boolean keySetChanged = true;
+ /*
+ * keysLock is used to brief synchronization when get selectionKeys snapshot
+ * before selection.
+ */
+ private static class KeysLock {}
+ final Object keysLock = new KeysLock();
private SelectionKey[] keys = new SelectionKey[1];
@@ -127,15 +128,15 @@
lastKeyIndex = 0;
readableKeysCount = 1;
-
} catch (IOException e) {
// do nothing
}
}
- /*
+ /**
* @see java.nio.channels.spi.AbstractSelector#implCloseSelector()
*/
+ @Override
protected void implCloseSelector() throws IOException {
synchronized (this) {
synchronized (keysSet) {
@@ -351,8 +352,10 @@
}
/**
+ * Note that the given key has been modified
*
* @param sk
+ * the modified key.
*/
void modKey(SelectionKey sk) {
// TODO: update indexes rather than recreate the key
@@ -360,10 +363,11 @@
addKey(sk);
}
- /*
+ /**
* @see java.nio.channels.spi.AbstractSelector#register(java.nio.channels.spi.AbstractSelectableChannel,
* int, java.lang.Object)
*/
+ @Override
protected SelectionKey register(AbstractSelectableChannel channel,
int operations, Object attachment) {
if (!provider().equals(channel.provider())) {
@@ -384,9 +388,10 @@
}
}
- /*
+ /**
* @see java.nio.channels.Selector#keys()
*/
+ @Override
public synchronized Set<SelectionKey> keys() {
closeCheck();
@@ -404,22 +409,27 @@
return unmodifiableKeys;
}
+ /*
+ * Checks that the receiver is not closed. If it is throws an exception.
+ */
private void closeCheck() {
if (!isOpen()) {
throw new ClosedSelectorException();
}
}
- /*
+ /**
* @see java.nio.channels.Selector#select()
*/
+ @Override
public int select() throws IOException {
return selectInternal(SELECT_BLOCK);
}
- /*
+ /**
* @see java.nio.channels.Selector#select(long)
*/
+ @Override
public int select(long timeout) throws IOException {
if (timeout < 0) {
throw new IllegalArgumentException();
@@ -427,9 +437,10 @@
return selectInternal((0 == timeout) ? SELECT_BLOCK : timeout);
}
- /*
+ /**
* @see java.nio.channels.Selector#selectNow()
*/
+ @Override
public int selectNow() throws IOException {
return selectInternal(SELECT_NOW);
}
@@ -468,7 +479,9 @@
return true;
}
- // Prepares and adds channels to list for selection
+ /*
+ * Prepares and adds channels to list for selection
+ */
private void prepareChannels() {
// chomp the arrays if needed
@@ -556,9 +569,10 @@
return selected;
}
- /*
+ /**
* @see java.nio.channels.Selector#selectedKeys()
*/
+ @Override
public synchronized Set<SelectionKey> selectedKeys() {
closeCheck();
return unaddableSelectedKeys;
@@ -579,9 +593,10 @@
}
}
- /*
+ /**
* @see java.nio.channels.Selector#wakeup()
*/
+ @Override
public Selector wakeup() {
try {
sink.write(ByteBuffer.allocate(MOCK_WRITEBUF_SIZE));
@@ -599,10 +614,12 @@
this.set = set;
}
+ @Override
public boolean equals(Object object) {
return set.equals(object);
}
+ @Override
public int hashCode() {
return set.hashCode();
}