package org.jboss.cx.remoting.jrpp.id;

import org.jboss.cx.remoting.core.util.Logger;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 *
 */
public abstract class JrppSubChannelIdentifier {
    private final short streamId;
    private final IdentifierManager manager;
    private final AtomicBoolean dead = new AtomicBoolean();

    private static final Logger log = Logger.getLogger(JrppSubChannelIdentifier.class);

    public JrppSubChannelIdentifier(IdentifierManager manager) throws IOException {
        this.manager = manager;
        streamId = this.manager.getIdentifier();
        if (streamId == 0) {
            throw new IOException("Channel is full");
        }
    }

    public synchronized void close() {
        if (! dead) {
            dead = true;
            manager.freeIdentifier(streamId);
        }
    }

    protected void finalize() throws Throwable {
        super.finalize();
        // for visibility of "dead"
        synchronized (this) {
            if (! dead) {
                log.trace("Leaked a subchannel instance");
                close();
            }
        }
    }

    public synchronized short getId() {
        if (dead) {
            throw new IllegalStateException("Read channel ID after close");
        }
        return streamId;
    }
}

@@ -774,36 +774,27 @@
 dead
-) %7B%0A            dead = true;
+.getAndSet(true)) %7B
 %0A   
@@ -932,78 +932,8 @@
 ();%0A
-        // for visibility of %22dead%22%0A        synchronized (this) %7B%0A    
     
@@ -942,32 +942,34 @@
   if (! dead
+.get()
 ) %7B%0A
-    
             
@@ -1023,20 +1023,16 @@
         
-    
 close();
@@ -1036,22 +1036,8 @@
 ();%0A
-            %7D%0A
     
@@ -1085,24 +1085,24 @@
 t getId() %7B%0A
-
         if (
@@ -1105,16 +1105,22 @@
 if (dead
+.get()
 ) %7B%0A    

Fix compile error