use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.
the class IOState method onConnected.
/**
* WebSocket has successfully upgraded, but the end-user onOpen call hasn't run yet.
* <p>
* This is an intermediate state between the RFC's {@link ConnectionState#CONNECTING} and {@link ConnectionState#OPEN}
*/
public void onConnected() {
ConnectionState event = null;
synchronized (this) {
if (this.state != ConnectionState.CONNECTING) {
LOG.debug("Unable to set to connected, not in CONNECTING state: {}", this.state);
return;
}
this.state = ConnectionState.CONNECTED;
// cannot read (yet)
inputAvailable = false;
// write allowed
outputAvailable = true;
event = this.state;
}
notifyStateListeners(event);
}
use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.
the class IOState method onAbnormalClose.
/**
* A websocket connection has been disconnected for abnormal close reasons.
* <p>
* This is the low level disconnect of the socket. It could be the result of a normal close operation, from an IO error, or even from a timeout.
* @param close the close information
*/
public void onAbnormalClose(CloseInfo close) {
if (LOG.isDebugEnabled())
LOG.debug("onAbnormalClose({})", close);
ConnectionState event = null;
synchronized (this) {
if (this.state == ConnectionState.CLOSED) {
// already closed
return;
}
if (this.state == ConnectionState.OPEN) {
this.cleanClose = false;
}
this.state = ConnectionState.CLOSED;
finalClose.compareAndSet(null, close);
this.inputAvailable = false;
this.outputAvailable = false;
this.closeHandshakeSource = CloseHandshakeSource.ABNORMAL;
event = this.state;
}
notifyStateListeners(event);
}
use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.
the class IOState method onOpened.
/**
* A websocket connection has finished its upgrade handshake, and is now open.
*/
public void onOpened() {
if (LOG.isDebugEnabled())
LOG.debug("onOpened()");
ConnectionState event = null;
synchronized (this) {
if (this.state == ConnectionState.OPEN) {
// already opened
return;
}
if (this.state != ConnectionState.CONNECTED) {
LOG.debug("Unable to open, not in CONNECTED state: {}", this.state);
return;
}
this.state = ConnectionState.OPEN;
this.inputAvailable = true;
this.outputAvailable = true;
event = this.state;
}
notifyStateListeners(event);
}
use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.
the class IOState method onCloseRemote.
/**
* A close handshake has been received from the remote endpoint
* @param closeInfo the close information
*/
public void onCloseRemote(CloseInfo closeInfo) {
if (LOG.isDebugEnabled())
LOG.debug("onCloseRemote({})", closeInfo);
ConnectionState event = null;
synchronized (this) {
if (this.state == ConnectionState.CLOSED) {
// already closed
return;
}
if (LOG.isDebugEnabled())
LOG.debug("onCloseRemote(), input={}, output={}", inputAvailable, outputAvailable);
this.closeInfo = closeInfo;
// turn off further input
inputAvailable = false;
if (closeHandshakeSource == CloseHandshakeSource.NONE) {
closeHandshakeSource = CloseHandshakeSource.REMOTE;
}
if (!outputAvailable) {
LOG.debug("Close Handshake satisfied, disconnecting");
cleanClose = true;
state = ConnectionState.CLOSED;
finalClose.compareAndSet(null, closeInfo);
event = this.state;
} else if (this.state == ConnectionState.OPEN) {
// We are now entering CLOSING (or half-closed)
this.state = ConnectionState.CLOSING;
event = this.state;
}
}
// Only notify on state change events
if (event != null) {
notifyStateListeners(event);
}
}
use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.
the class IOState method closeLocal.
private void closeLocal(CloseInfo closeInfo) {
ConnectionState event = null;
ConnectionState abnormalEvent = null;
synchronized (this) {
if (LOG.isDebugEnabled())
LOG.debug("onCloseLocal(), input={}, output={}", inputAvailable, outputAvailable);
this.closeInfo = closeInfo;
// Turn off further output.
outputAvailable = false;
if (closeHandshakeSource == CloseHandshakeSource.NONE) {
closeHandshakeSource = CloseHandshakeSource.LOCAL;
}
if (!inputAvailable) {
if (LOG.isDebugEnabled())
LOG.debug("Close Handshake satisfied, disconnecting");
cleanClose = true;
this.state = ConnectionState.CLOSED;
finalClose.compareAndSet(null, closeInfo);
event = this.state;
} else if (this.state == ConnectionState.OPEN) {
// We are now entering CLOSING (or half-closed).
this.state = ConnectionState.CLOSING;
event = this.state;
// If abnormal, we don't expect an answer.
if (closeInfo.isAbnormal()) {
abnormalEvent = ConnectionState.CLOSED;
finalClose.compareAndSet(null, closeInfo);
cleanClose = false;
outputAvailable = false;
inputAvailable = false;
closeHandshakeSource = CloseHandshakeSource.ABNORMAL;
}
}
}
// Only notify on state change events
if (event != null) {
notifyStateListeners(event);
if (abnormalEvent != null) {
notifyStateListeners(abnormalEvent);
}
}
}
Aggregations