//
// ========================================================================
-// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
+// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
public abstract class AbstractConnection implements Connection
{
private static final Logger LOG = Log.getLogger(AbstractConnection.class);
-
+
public static final boolean EXECUTE_ONFILLABLE=true;
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
{
this(endp,executor,EXECUTE_ONFILLABLE);
}
-
+
protected AbstractConnection(EndPoint endp, Executor executor, final boolean executeOnfillable)
{
if (executor == null)
{
return _executor;
}
-
+
protected void failedCallback(final Callback callback, final Throwable x)
{
if (NonBlockingThread.isNonBlockingThread())
callback.failed(x);
}
}
-
+
/**
* <p>Utility method to be called to register read interest.</p>
* <p>After a call to this method, {@link #onFillable()} or {@link #onFillInterestedFailed(Throwable)}
*/
public void fillInterested()
{
- LOG.debug("fillInterested {}",this);
-
+ if (LOG.isDebugEnabled())
+ LOG.debug("fillInterested {}",this);
+
while(true)
{
State state=_state.get();
break;
}
}
-
+
public void fillInterested(Callback callback)
{
- LOG.debug("fillInterested {}",this);
+ if (LOG.isDebugEnabled())
+ LOG.debug("fillInterested {}",this);
while(true)
{
break;
}
}
-
+
/**
* <p>Callback method invoked when the endpoint is ready to be read.</p>
* @see #fillInterested()
*/
protected void onFillInterestedFailed(Throwable cause)
{
- LOG.debug("{} onFillInterestedFailed {}", this, cause);
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onFillInterestedFailed {}", this, cause);
if (_endPoint.isOpen())
{
boolean close = true;
}
if (_endPoint.isOpen())
- fillInterested();
+ fillInterested();
}
/**
@Override
public void onOpen()
{
- LOG.debug("onOpen {}", this);
+ if (LOG.isDebugEnabled())
+ LOG.debug("onOpen {}", this);
for (Listener listener : listeners)
listener.onOpened(this);
@Override
public void onClose()
{
- LOG.debug("onClose {}",this);
+ if (LOG.isDebugEnabled())
+ LOG.debug("onClose {}",this);
for (Listener listener : listeners)
listener.onClosed(this);
@Override
public String toString()
{
- return String.format("%s@%x{%s}", getClass().getSimpleName(), hashCode(), _state.get());
+ return String.format("%s@%x[%s,%s]",
+ getClass().getSimpleName(),
+ hashCode(),
+ _state.get(),
+ _endPoint);
}
-
+
public boolean next(State state, State next)
{
if (next==null)
return true;
if(_state.compareAndSet(state,next))
{
- LOG.debug("{}-->{} {}",state,next,this);
+ if (LOG.isDebugEnabled())
+ LOG.debug("{}-->{} {}",state,next,this);
if (next!=state)
next.onEnter(AbstractConnection.this);
return true;
}
return false;
}
-
+
private static final class IdleState extends State
{
private IdleState()
{
return _name;
}
-
+
void onEnter(AbstractConnection connection)
{
}
-
+
State fillInterested()
{
throw new IllegalStateException(this.toString());
{
throw new IllegalStateException(this.toString());
}
-
+
State onFailed()
{
throw new IllegalStateException(this.toString());
}
}
-
+
public static final State IDLE=new IdleState();
-
+
public static final State FILL_INTERESTED=new FillInterestedState();
-
+
public static final State FILLING=new FillingState();
-
+
public static final State REFILLING=new RefillingState();
public static final State FILLING_FILL_INTERESTED=new FillingFillInterestedState("FILLING_FILL_INTERESTED");
-
+
public class NestedState extends State
{
private final State _nested;
-
+
NestedState(State nested)
{
super("NESTED("+nested+")");
{
return new NestedState(_nested.onFillable());
}
-
+
@Override
State onFilled()
{
return new NestedState(_nested.onFilled());
}
}
-
-
+
+
public class FillingInterestedCallback extends NestedState
{
private final Callback _callback;
-
+
FillingInterestedCallback(Callback callback,State nested)
{
super("FILLING_INTERESTED_CALLBACK",nested==FILLING?REFILLING:nested);
break;
}
_callback.failed(x);
- }
+ }
};
-
+
connection.getEndPoint().fillInterested(callback);
}
}
-
+
private final Runnable _runOnFillable = new Runnable()
{
@Override
}
}
};
-
-
+
+
private class ReadCallback implements Callback
- {
+ {
@Override
public void succeeded()
{
}
});
}
-
+
@Override
public String toString()
{