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 2006/12/22 14:30:03 UTC
svn commit: r489649 - in /harmony/enhanced/classlib/trunk/modules/nio/src:
main/java/java/nio/channels/spi/ main/java/org/apache/harmony/nio/internal/
test/java/common/org/apache/harmony/nio/tests/java/nio/channels/
Author: tellison
Date: Fri Dec 22 05:30:02 2006
New Revision: 489649
URL: http://svn.apache.org/viewvc?view=rev&rev=489649
Log:
Fix some minor compiler warnings, and test warning.
Modified:
harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractInterruptibleChannel.java
harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java
harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/SelectorProvider.java
harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java
harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractInterruptibleChannel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractInterruptibleChannel.java?view=diff&rev=489649&r1=489648&r2=489649
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractInterruptibleChannel.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractInterruptibleChannel.java Fri Dec 22 05:30:02 2006
@@ -38,143 +38,143 @@
*
*/
public abstract class AbstractInterruptibleChannel implements Channel,
- InterruptibleChannel {
+ InterruptibleChannel {
- static Method setInterruptAction = null;
+ static Method setInterruptAction = null;
- static {
- try {
- setInterruptAction = AccessController
- .doPrivileged(new PrivilegedExceptionAction<Method>() {
- public Method run() throws Exception {
- return Thread.class.getDeclaredMethod(
- "setInterruptAction", //$NON-NLS-1$
- new Class[] { Runnable.class });
-
- }
- });
- setInterruptAction.setAccessible(true);
- } catch (Exception e) {
- // FIXME: be accommodate before VM actually provides
- // setInterruptAction method
- // throw new Error(e);
- }
- }
-
- private volatile boolean closed = false;
-
- volatile boolean interrupted = false;
-
- /**
- * Default constructor.
- */
- protected AbstractInterruptibleChannel() {
- super();
- }
-
- /**
- * Answers whether the channel is open.
- *
- * @return true if the channel is open, and false if it is closed.
- * @see java.nio.channels.Channel#isOpen()
- */
- public synchronized final boolean isOpen() {
- return !closed;
- }
-
- /**
- * Closes the channel.
- * <p>
- * If the channel is already closed then this method has no effect,
- * otherwise it closes the receiver via the implCloseChannel method.
- * </p>
- *
- * @see java.nio.channels.Channel#close()
- */
- public final void close() throws IOException {
- if (!closed) {
- synchronized (this) {
- if (!closed) {
- closed = true;
- implCloseChannel();
- }
- }
- }
- }
-
- /**
- * Start an IO operation that is potentially blocking.
- * <p>
- * Once the operation is completed the application should invoke a
- * corresponding <code>end(boolean)</code>.
- */
- protected final void begin() {
- // FIXME: be accommodate before VM actually provides
- // setInterruptAction method
- if (setInterruptAction != null) {
- try {
- setInterruptAction.invoke(Thread.currentThread(),
- new Object[] { new Runnable() {
- public void run() {
- try {
- interrupted = true;
- AbstractInterruptibleChannel.this.close();
- } catch (IOException e) {
- // ignore
- }
- }
- } });
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- /**
- * End an IO operation that was previously started with <code>begin()</code>.
- *
- * @param success
- * pass true if the operation succeeded and had a side effect on
- * the Java system, or false if not.
- * @throws AsynchronousCloseException
- * the channel was closed while the IO operation was in
- * progress.
- * @throws java.nio.channels.ClosedByInterruptException
- * the thread conducting the IO operation was interrupted.
- */
- protected final void end(boolean success) throws AsynchronousCloseException {
- // FIXME: be accommodate before VM actually provides
- // setInterruptAction method
- if (setInterruptAction != null) {
- try {
- setInterruptAction.invoke(Thread.currentThread(),
- new Object[] { null });
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- if (interrupted) {
- interrupted = false;
- throw new ClosedByInterruptException();
- }
- }
- if (!success && closed) {
- throw new AsynchronousCloseException();
- }
- }
-
- /**
- * Implements the close channel behavior.
- * <p>
- * Closes the channel with a guarantee that the channel is not currently
- * closed via <code>close()</code> and that the method is thread-safe.
- * </p>
- * <p>
- * any outstanding threads blocked on IO operations on this channel must be
- * released with either a normal return code, or an
- * <code>AsynchronousCloseException</code>.
- *
- * @throws IOException
- * if a problem occurs closing the channel.
- */
- protected abstract void implCloseChannel() throws IOException;
+ static {
+ try {
+ setInterruptAction = AccessController
+ .doPrivileged(new PrivilegedExceptionAction<Method>() {
+ public Method run() throws Exception {
+ return Thread.class.getDeclaredMethod(
+ "setInterruptAction", //$NON-NLS-1$
+ new Class[] { Runnable.class });
+
+ }
+ });
+ setInterruptAction.setAccessible(true);
+ } catch (Exception e) {
+ // FIXME: be accommodate before VM actually provides
+ // setInterruptAction method
+ // throw new Error(e);
+ }
+ }
+
+ private volatile boolean closed = false;
+
+ volatile boolean interrupted = false;
+
+ /**
+ * Default constructor.
+ */
+ protected AbstractInterruptibleChannel() {
+ super();
+ }
+
+ /**
+ * Answers whether the channel is open.
+ *
+ * @return true if the channel is open, and false if it is closed.
+ * @see java.nio.channels.Channel#isOpen()
+ */
+ public synchronized final boolean isOpen() {
+ return !closed;
+ }
+
+ /**
+ * Closes the channel.
+ * <p>
+ * If the channel is already closed then this method has no effect,
+ * otherwise it closes the receiver via the implCloseChannel method.
+ * </p>
+ *
+ * @see java.nio.channels.Channel#close()
+ */
+ public final void close() throws IOException {
+ if (!closed) {
+ synchronized (this) {
+ if (!closed) {
+ closed = true;
+ implCloseChannel();
+ }
+ }
+ }
+ }
+
+ /**
+ * Start an IO operation that is potentially blocking.
+ * <p>
+ * Once the operation is completed the application should invoke a
+ * corresponding <code>end(boolean)</code>.
+ */
+ protected final void begin() {
+ // FIXME: be accommodate before VM actually provides
+ // setInterruptAction method
+ if (setInterruptAction != null) {
+ try {
+ setInterruptAction.invoke(Thread.currentThread(),
+ new Object[] { new Runnable() {
+ public void run() {
+ try {
+ interrupted = true;
+ AbstractInterruptibleChannel.this.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ } });
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ /**
+ * End an IO operation that was previously started with <code>begin()</code>.
+ *
+ * @param success
+ * pass true if the operation succeeded and had a side effect on
+ * the Java system, or false if not.
+ * @throws AsynchronousCloseException
+ * the channel was closed while the IO operation was in
+ * progress.
+ * @throws java.nio.channels.ClosedByInterruptException
+ * the thread conducting the IO operation was interrupted.
+ */
+ protected final void end(boolean success) throws AsynchronousCloseException {
+ // FIXME: be accommodate before VM actually provides
+ // setInterruptAction method
+ if (setInterruptAction != null) {
+ try {
+ setInterruptAction.invoke(Thread.currentThread(),
+ new Object[] { null });
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ if (interrupted) {
+ interrupted = false;
+ throw new ClosedByInterruptException();
+ }
+ }
+ if (!success && closed) {
+ throw new AsynchronousCloseException();
+ }
+ }
+
+ /**
+ * Implements the close channel behavior.
+ * <p>
+ * Closes the channel with a guarantee that the channel is not currently
+ * closed via <code>close()</code> and that the method is thread-safe.
+ * </p>
+ * <p>
+ * any outstanding threads blocked on IO operations on this channel must be
+ * released with either a normal return code, or an
+ * <code>AsynchronousCloseException</code>.
+ *
+ * @throws IOException
+ * if a problem occurs closing the channel.
+ */
+ protected abstract void implCloseChannel() throws IOException;
}
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java?view=diff&rev=489649&r1=489648&r2=489649
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java Fri Dec 22 05:30:02 2006
@@ -45,7 +45,9 @@
*/
private List<SelectionKey> keyList = new ArrayList<SelectionKey>();
- private class BlockingLock {}
+ private class BlockingLock {
+ }
+
private final Object blockingLock = new BlockingLock();
boolean isBlocking = true;
@@ -83,7 +85,7 @@
*/
synchronized public final SelectionKey keyFor(Selector selector) {
for (int i = 0; i < keyList.size(); i++) {
- SelectionKey key = (SelectionKey) keyList.get(i);
+ SelectionKey key = keyList.get(i);
if (null != key && key.selector() == selector) {
return key;
}
@@ -119,14 +121,14 @@
throw new IllegalBlockingModeException();
}
if (!selector.isOpen()) {
- if (0 == interestSet){
+ if (0 == interestSet) {
// throw ISE exactly to keep consistency
throw new IllegalSelectorException();
}
// throw NPE exactly to keep consistency
throw new NullPointerException();
}
- if (0 == interestSet){
+ if (0 == interestSet) {
// throw ISE exactly to keep consistency
throw new IllegalSelectorException();
}
@@ -154,7 +156,7 @@
synchronized protected final void implCloseChannel() throws IOException {
implCloseSelectableChannel();
for (int i = 0; i < keyList.size(); i++) {
- SelectionKey key = (SelectionKey) keyList.get(i);
+ SelectionKey key = keyList.get(i);
if (null != key) {
key.cancel();
}
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/SelectorProvider.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/SelectorProvider.java?view=diff&rev=489649&r1=489648&r2=489649
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/SelectorProvider.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/channels/spi/SelectorProvider.java Fri Dec 22 05:30:02 2006
@@ -111,7 +111,7 @@
* load the provider in the jar file of class path.
*/
static SelectorProvider loadProviderByJar() {
- Enumeration enumeration = null;
+ Enumeration<URL> enumeration = null;
ClassLoader classLoader = AccessController.doPrivileged(
new PrivilegedAction<ClassLoader>() {
@@ -133,7 +133,7 @@
String className = null;
try {
br = new BufferedReader(new InputStreamReader(
- ((URL) enumeration.nextElement()).openStream()));
+ (enumeration.nextElement()).openStream()));
} catch (Exception e) {
continue;
}
@@ -168,7 +168,7 @@
final String className =
System.getProperty(PROVIDER_IN_SYSTEM_PROPERTY);
if (null != className) {
- Class spClass = ClassLoader
+ Class<?> spClass = ClassLoader
.getSystemClassLoader().loadClass(
className);
return (SelectorProvider)spClass.newInstance();
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java?view=diff&rev=489649&r1=489648&r2=489649
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java Fri Dec 22 05:30:02 2006
@@ -190,7 +190,7 @@
private void prepareChannels() {
readableChannels.add(source);
synchronized (keysLock) {
- for (Iterator i = keys.iterator(); i.hasNext();) {
+ for (Iterator<SelectionKey> i = keys.iterator(); i.hasNext();) {
SelectionKeyImpl key = (SelectionKeyImpl) i.next();
key.oldInterestOps = key.interestOps();
boolean isReadableChannel = ((SelectionKey.OP_ACCEPT | SelectionKey.OP_READ) & key.oldInterestOps) != 0;
@@ -203,10 +203,8 @@
}
}
}
- readable = (SelectableChannel[]) readableChannels
- .toArray(new SelectableChannel[0]);
- writable = (SelectableChannel[]) writableChannels
- .toArray(new SelectableChannel[0]);
+ readable = readableChannels.toArray(new SelectableChannel[0]);
+ writable = writableChannels.toArray(new SelectableChannel[0]);
readableChannels.clear();
writableChannels.clear();
}
@@ -386,7 +384,7 @@
}
public <T> T[] toArray(T[] a) {
- return (T[]) set.toArray(a);
+ return set.toArray(a);
}
}
}
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java?view=diff&rev=489649&r1=489648&r2=489649
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java Fri Dec 22 05:30:02 2006
@@ -98,9 +98,6 @@
// connect success
private static final int CONNECT_SUCCESS = 0;
- // a address of localhost
- private static final byte[] localAddrArray = { 127, 0, 0, 1 };
-
// -------------------------------------------------------------------
// Instance Variables
// -------------------------------------------------------------------
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java?view=diff&rev=489649&r1=489648&r2=489649
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java Fri Dec 22 05:30:02 2006
@@ -1421,8 +1421,7 @@
try {
connected = this.channel1.finishConnect();
} catch (SocketException e) {
- System.err
- .println("Finish connection failed, probably due to reset by peer error.");
+ // Finish connection failed, probably due to reset by peer error.
}
if (connected) {
statusConnected_NotPending();