use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocol in project orientdb by orientechnologies.
the class OClientConnectionManager method kill.
/**
* Disconnects and kill the associated network manager.
*
* @param connection
* connection to kill
*/
public void kill(final OClientConnection connection) {
if (connection != null) {
final ONetworkProtocol protocol = connection.getProtocol();
try {
// INTERRUPT THE NEWTORK MANAGER TOO
protocol.interrupt();
} catch (Exception e) {
OLogManager.instance().error(this, "Error during interruption of binary protocol", e);
}
disconnect(connection);
// KILL THE NETWORK MANAGER TOO
protocol.sendShutdown();
}
}
use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocol in project orientdb by orientechnologies.
the class OClientConnectionManager method shutdown.
public void shutdown() {
timerTask.cancel();
List<ONetworkProtocol> toWait = new ArrayList<ONetworkProtocol>();
final Iterator<Entry<Integer, OClientConnection>> iterator = connections.entrySet().iterator();
while (iterator.hasNext()) {
final Entry<Integer, OClientConnection> entry = iterator.next();
final ONetworkProtocol protocol = entry.getValue().getProtocol();
if (protocol != null)
protocol.sendShutdown();
OLogManager.instance().debug(this, "Sending shutdown to thread %s", protocol);
OCommandRequestText command = entry.getValue().getData().command;
if (command != null && command.isIdempotent()) {
protocol.interrupt();
} else {
if (protocol instanceof ONetworkProtocolBinary && ((ONetworkProtocolBinary) protocol).getRequestType() == OChannelBinaryProtocol.REQUEST_SHUTDOWN) {
continue;
}
final Socket socket;
if (protocol == null || protocol.getChannel() == null)
socket = null;
else
socket = protocol.getChannel().socket;
if (socket != null && !socket.isClosed() && !socket.isInputShutdown()) {
try {
OLogManager.instance().debug(this, "Closing input socket of thread %s", protocol);
if (// An SSLSocket will throw an UnsupportedOperationException.
!(socket instanceof SSLSocket))
socket.shutdownInput();
} catch (IOException e) {
OLogManager.instance().debug(this, "Error on closing connection of %s client during shutdown", e, entry.getValue().getRemoteAddress());
}
}
if (protocol.isAlive()) {
if (protocol instanceof ONetworkProtocolBinary && ((ONetworkProtocolBinary) protocol).getRequestType() == -1) {
try {
OLogManager.instance().debug(this, "Closing socket of thread %s", protocol);
protocol.getChannel().close();
} catch (Exception e) {
OLogManager.instance().debug(this, "Error during chanel close at shutdown", e);
}
OLogManager.instance().debug(this, "Sending interrupt signal to thread %s", protocol);
protocol.interrupt();
}
toWait.add(protocol);
}
}
}
for (ONetworkProtocol protocol : toWait) {
try {
protocol.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocol in project orientdb by orientechnologies.
the class OServer method activate.
@SuppressWarnings("unchecked")
public OServer activate() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
try {
serverSecurity = new ODefaultServerSecurity(this, serverCfg);
Orient.instance().setSecurity(serverSecurity);
// Checks to see if the OrientDB System Database exists and creates it if not.
// Make sure this happens after setSecurityFactory() is called.
initSystemDatabase();
for (OServerLifecycleListener l : lifecycleListeners) l.onBeforeActivate();
final OServerConfiguration configuration = serverCfg.getConfiguration();
tokenHandler = new OTokenHandlerImpl(this);
if (configuration.network != null) {
// REGISTER/CREATE SOCKET FACTORIES
if (configuration.network.sockets != null) {
for (OServerSocketFactoryConfiguration f : configuration.network.sockets) {
Class<? extends OServerSocketFactory> fClass = (Class<? extends OServerSocketFactory>) loadClass(f.implementation);
OServerSocketFactory factory = fClass.newInstance();
try {
factory.config(f.name, f.parameters);
networkSocketFactories.put(f.name, factory);
} catch (OConfigurationException e) {
OLogManager.instance().error(this, "Error creating socket factory", e);
}
}
}
// REGISTER PROTOCOLS
for (OServerNetworkProtocolConfiguration p : configuration.network.protocols) networkProtocols.put(p.name, (Class<? extends ONetworkProtocol>) loadClass(p.implementation));
// STARTUP LISTENERS
for (OServerNetworkListenerConfiguration l : configuration.network.listeners) networkListeners.add(new OServerNetworkListener(this, networkSocketFactories.get(l.socket), l.ipAddress, l.portRange, l.protocol, networkProtocols.get(l.protocol), l.parameters, l.commands));
} else
OLogManager.instance().warn(this, "Network configuration was not found");
try {
loadStorages();
loadUsers();
loadDatabases();
} catch (IOException e) {
final String message = "Error on reading server configuration";
OLogManager.instance().error(this, message, e);
throw OException.wrapException(new OConfigurationException(message), e);
}
registerPlugins();
for (OServerLifecycleListener l : lifecycleListeners) l.onAfterActivate();
running = true;
String httpAddress = "localhost:2480";
for (OServerNetworkListener listener : getNetworkListeners()) {
if (listener.getProtocolType().getName().equals(ONetworkProtocolHttpDb.class.getName()))
httpAddress = listener.getListeningAddress(true);
}
OLogManager.instance().info(this, "OrientDB Studio available at $ANSI{blue http://%s/studio/index.html}", httpAddress);
OLogManager.instance().info(this, "$ANSI{green:italic OrientDB Server is active} v" + OConstants.getVersion() + ".");
} catch (ClassNotFoundException e) {
running = false;
throw e;
} catch (InstantiationException e) {
running = false;
throw e;
} catch (IllegalAccessException e) {
running = false;
throw e;
} catch (RuntimeException e) {
running = false;
throw e;
} finally {
startupLatch.countDown();
}
return this;
}
use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocol in project orientdb by orientechnologies.
the class OServerNetworkListener method run.
@Override
public void run() {
try {
while (active) {
try {
// listen for and accept a client connection to serverSocket
final Socket socket = serverSocket.accept();
final int max = OGlobalConfiguration.NETWORK_MAX_CONCURRENT_SESSIONS.getValueAsInteger();
int conns = server.getClientConnectionManager().getTotal();
if (conns >= max) {
server.getClientConnectionManager().cleanExpiredConnections();
conns = server.getClientConnectionManager().getTotal();
if (conns >= max) {
// MAXIMUM OF CONNECTIONS EXCEEDED
OLogManager.instance().warn(this, "Reached maximum number of concurrent connections (max=%d, current=%d), reject incoming connection from %s", max, conns, socket.getRemoteSocketAddress());
socket.close();
// PAUSE CURRENT THREAD TO SLOW DOWN ANY POSSIBLE ATTACK
Thread.sleep(100);
continue;
}
}
socket.setPerformancePreferences(0, 2, 1);
if (socketBufferSize > 0) {
socket.setSendBufferSize(socketBufferSize);
socket.setReceiveBufferSize(socketBufferSize);
}
// CREATE A NEW PROTOCOL INSTANCE
final ONetworkProtocol protocol = protocolType.newInstance();
// CONFIGURE THE PROTOCOL FOR THE INCOMING CONNECTION
protocol.config(this, server, socket, configuration);
} catch (Throwable e) {
if (active)
OLogManager.instance().error(this, "Error on client connection", e);
} finally {
}
}
} finally {
try {
if (serverSocket != null && !serverSocket.isClosed())
serverSocket.close();
} catch (IOException ioe) {
}
}
}
use of com.orientechnologies.orient.server.network.protocol.ONetworkProtocol in project orientdb by orientechnologies.
the class OClientConnectionManager method killAllChannels.
public void killAllChannels() {
for (Map.Entry<Integer, OClientConnection> entry : connections.entrySet()) {
try {
ONetworkProtocol protocol = entry.getValue().getProtocol();
protocol.getChannel().close();
final Socket socket;
if (protocol == null || protocol.getChannel() == null)
socket = null;
else
socket = protocol.getChannel().socket;
if (socket != null && !socket.isClosed() && !socket.isInputShutdown()) {
if (// An SSLSocket will throw an UnsupportedOperationException.
!(socket instanceof SSLSocket))
socket.shutdownInput();
}
} catch (Exception e) {
OLogManager.instance().debug(this, "Error on killing connection to %s client", e, entry.getValue().getRemoteAddress());
}
}
}
Aggregations