CloseableReferenceCount { public int setClosed() throws ClosedChannelException { while (true) { int curBits = status.get(); if ((curBits & STATUS_CLOSED_MASK) != 0) { throw new ClosedChannelException(); } if (status.compareAndSet(curBits, curBits | STATUS_CLOSED_MASK)) { return curBits & (~STATUS_CLOSED_MASK); } } } CloseableReferenceCount(); void reference(); boolean unreference(); void unreferenceCheckClosed(); boolean isOpen(); int setClosed(); int getReferenceCount();  }
@Test public void testSetClosed() throws ClosedChannelException { CloseableReferenceCount clr = new CloseableReferenceCount(); assertTrue("Reference count should be open", clr.isOpen()); clr.setClosed(); assertFalse("Reference count should be closed", clr.isOpen()); }