com.zipwhip.api.signals.sockets.netty.ChannelWrapperConnectionHandle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zipwhip-api Show documentation
Show all versions of zipwhip-api Show documentation
Java client to support applications powered by the Zipwhip Cloud
The newest version!
package com.zipwhip.api.signals.sockets.netty;
import com.zipwhip.api.signals.Writable;
import com.zipwhip.api.signals.sockets.ConnectionHandle;
import com.zipwhip.concurrent.ObservableFuture;
/**
* Created with IntelliJ IDEA.
* User: msmyers
* Date: 9/4/12
* Time: 2:20 PM
*
* This class allows callers to have "correct ensureAbleTo" to the underlying connection. They might need to disconnect
* THE SPECIFIC connection that they created. If another connection has taken its place then they want to just noop.
*/
public class ChannelWrapperConnectionHandle extends SignalConnectionBaseConnectionHandleBase implements ConnectionHandle, Writable {
public ChannelWrapper channelWrapper;
// we use pause to prevent any concurrent ensureAbleTo. Is this needed?
public ChannelWrapperConnectionHandle(long id, SignalConnectionBase signalConnectionBase, ChannelWrapper channelWrapper) {
super(id, signalConnectionBase);
this.channelWrapper = channelWrapper;
}
@Override
public ObservableFuture write(Object object) {
if (isDestroyed()){
throw new IllegalAccessError("The connection is destroyed and you tried to 'write'");
} else if (channelWrapper == null) {
throw new IllegalAccessError("The channelWrapper is null and you tried to 'write'!");
}
return channelWrapper.write(object);
}
@Override
protected void onDestroy() {
super.onDestroy();
channelWrapper = null;
}
@Override
public String toString() {
if (channelWrapper == null){
return "[ChannelWrapperConnectionHandle: null]";
} else {
return String.format("[ChannelWrapperConnectionHandle: %s]", channelWrapper.channel);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy