< prev index next >

src/java.base/share/classes/sun/nio/ch/SelectionKeyImpl.java

Print this page
rev 49242 : [mq]: selector-cleanup

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -23,13 +23,15 @@
  * questions.
  */
 
 package sun.nio.ch;
 
-import java.io.IOException;
-import java.nio.channels.*;
-import java.nio.channels.spi.*;
+import java.nio.channels.CancelledKeyException;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.spi.AbstractSelectionKey;
 
 
 /**
  * An implementation of SelectionKey for Solaris.
  */

@@ -43,11 +45,11 @@
 
     // Index for a pollfd array in Selector that this key is registered with
     private int index;
 
     private volatile int interestOps;
-    private int readyOps;
+    private volatile int readyOps;
 
     SelectionKeyImpl(SelChImpl ch, SelectorImpl sel) {
         channel = ch;
         selector = sel;
     }

@@ -109,6 +111,24 @@
 
     public int nioInterestOps() {
         return interestOps;
     }
 
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("channel=")
+          .append(channel)
+          .append(", selector=")
+          .append(selector);
+        if (isValid()) {
+            sb.append(", interestOps=")
+              .append(interestOps)
+              .append(", readyOps=")
+              .append(readyOps);
+        } else {
+            sb.append(", invalid");
+        }
+        return sb.toString();
+    }
+
 }
< prev index next >