use of com.orientechnologies.orient.server.OClientConnection in project orientdb by orientechnologies.
the class OLiveCommandResultListener method onLiveResult.
public void onLiveResult(int iToken, ORecordOperation iOp) throws OException {
boolean sendFail = true;
do {
List<OClientConnection> connections = session.getConnections();
if (connections.size() == 0) {
try {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
OLogManager.instance().warn(this, "Unsubscribing live query for connection " + connection);
OLiveQueryHook.unsubscribe(iToken, db);
} catch (Exception e) {
OLogManager.instance().warn(this, "Unsubscribing live query for connection " + connection, e);
}
break;
}
OClientConnection curConnection = connections.get(0);
ONetworkProtocolBinary protocol = (ONetworkProtocolBinary) curConnection.getProtocol();
OChannelBinary channel = protocol.getChannel();
try {
channel.acquireWriteLock();
try {
ByteArrayOutputStream content = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(content);
out.writeByte('r');
out.writeByte(iOp.type);
out.writeInt(iToken);
out.writeByte(ORecordInternal.getRecordType(iOp.getRecord()));
writeVersion(out, iOp.getRecord().getVersion());
writeRID(out, (ORecordId) iOp.getRecord().getIdentity());
writeBytes(out, protocol.getRecordBytes(connection, iOp.getRecord()));
channel.writeByte(OChannelBinaryProtocol.PUSH_DATA);
channel.writeInt(Integer.MIN_VALUE);
channel.writeByte(OChannelBinaryProtocol.REQUEST_PUSH_LIVE_QUERY);
channel.writeBytes(content.toByteArray());
channel.flush();
} finally {
channel.releaseWriteLock();
}
sendFail = false;
} catch (IOException e) {
session.removeConnection(curConnection);
connections = session.getConnections();
if (connections.isEmpty()) {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
OLiveQueryHook.unsubscribe(iToken, db);
break;
}
} catch (Exception e) {
OLogManager.instance().warn(this, "Cannot push cluster configuration to the client %s", e, protocol.getRemoteAddress());
protocol.getServer().getClientConnectionManager().disconnect(connection);
OLiveQueryHook.unsubscribe(iToken, connection.getDatabase());
break;
}
} while (sendFail);
}
use of com.orientechnologies.orient.server.OClientConnection in project orientdb by orientechnologies.
the class OServerCommandPostKillDbConnection method doPost.
private void doPost(OHttpRequest iRequest, OHttpResponse iResponse, String db, String command) throws IOException {
final List<OClientConnection> connections = server.getClientConnectionManager().getConnections();
for (OClientConnection connection : connections) {
if (connection.getProtocol() instanceof ONetworkProtocolHttpAbstract) {
final ONetworkProtocolHttpAbstract http = (ONetworkProtocolHttpAbstract) connection.getProtocol();
final OHttpRequest req = http.getRequest();
if (req != null && req != iRequest && req.sessionId.equals(iRequest.sessionId)) {
server.getClientConnectionManager().interrupt(connection.getId());
}
}
}
iResponse.send(OHttpUtils.STATUS_OK_NOCONTENT_CODE, OHttpUtils.STATUS_OK_NOCONTENT_DESCRIPTION, OHttpUtils.CONTENT_TEXT_PLAIN, null, null);
}
use of com.orientechnologies.orient.server.OClientConnection in project orientdb by orientechnologies.
the class OLiveCommandResultListener method onUnsubscribe.
@Override
public void onUnsubscribe(int iLiveToken) {
boolean sendFail = true;
do {
List<OClientConnection> connections = session.getConnections();
if (connections.size() == 0) {
break;
}
ONetworkProtocolBinary protocol = (ONetworkProtocolBinary) connections.get(0).getProtocol();
OChannelBinary channel = protocol.getChannel();
try {
channel.acquireWriteLock();
try {
ByteArrayOutputStream content = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(content);
out.writeByte('u');
out.writeInt(iLiveToken);
channel.writeByte(OChannelBinaryProtocol.PUSH_DATA);
channel.writeInt(Integer.MIN_VALUE);
channel.writeByte(OChannelBinaryProtocol.REQUEST_PUSH_LIVE_QUERY);
channel.writeBytes(content.toByteArray());
channel.flush();
} finally {
channel.releaseWriteLock();
}
sendFail = false;
} catch (IOException e) {
connections = session.getConnections();
if (connections.isEmpty()) {
break;
}
} catch (Exception e) {
OLogManager.instance().warn(this, "Cannot push cluster configuration to the client %s", e, protocol.getRemoteAddress());
protocol.getServer().getClientConnectionManager().disconnect(connection);
break;
}
} while (sendFail);
}
use of com.orientechnologies.orient.server.OClientConnection in project orientdb by orientechnologies.
the class ONetworkProtocolBinary method execute.
@Override
protected void execute() throws Exception {
requestType = -1;
// do not remove this or we will get deadlock upon shutdown.
if (isShutdownFlag())
return;
clientTxId = 0;
okSent = false;
try {
requestType = channel.readByte();
OChannelBinaryProtocol.checkRequestTypeRange(channel, requestType);
clientTxId = channel.readInt();
// GET THE CONNECTION IF EXIST
OClientConnection connection = server.getClientConnectionManager().getConnection(clientTxId, this);
if (isHandshaking(requestType)) {
handshakeRequest(connection, requestType, clientTxId);
} else if (isDistributed(requestType)) {
distributedRequest(connection, requestType, clientTxId);
} else
sessionRequest(connection, requestType, clientTxId);
} catch (Exception e) {
// if an exception arrive to this point we need to kill the current socket.
sendShutdown();
throw e;
}
}
Aggregations