public OStorage registerStorage(final OStorage iStorage) throws IOException { acquireExclusiveLock(); try { for (OOrientListener l : listeners) l.onStorageRegistered(iStorage); if (!storages.containsKey(iStorage.getName())) storages.put(iStorage.getName(), iStorage); } finally { releaseExclusiveLock(); } return iStorage; }
public void shutdown() { acquireExclusiveLock(); try { if (!active) return; active = false; if (shutdownHook != null) shutdownHook.cancel(); if (profiler != null) profiler.shutdown(); OLogManager.instance().debug(this, "Orient Engine is shutting down..."); if (listeners != null) // CALL THE SHUTDOWN ON ALL THE LISTENERS for (OOrientListener l : listeners) { if (l != null) l.onShutdown(); } // SHUTDOWN ENGINES for (OEngine engine : engines.values()) { engine.shutdown(); } if (databaseFactory != null) // CLOSE ALL DATABASES databaseFactory.shutdown(); if (storages != null) { // CLOSE ALL THE STORAGES final List<OStorage> storagesCopy = new ArrayList<OStorage>(storages.values()); for (OStorage stg : storagesCopy) { OLogManager.instance().info(this, "Shutting down storage: " + stg.getName() + "..."); stg.close(true); } } if (OMMapManagerLocator.getInstance() != null) OMMapManagerLocator.getInstance().shutdown(); if (threadGroup != null) // STOP ALL THE PENDING THREADS threadGroup.interrupt(); if (listeners != null) listeners.clear(); OLogManager.instance().info(this, "Orient Engine shutdown complete\n"); } finally { releaseExclusiveLock(); } }
/** * Drops a database from a remote server instance. * * @param iDatabaseName The database name * @param storageType Storage type between "plocal" or "memory". * @return The instance itself. Useful to execute method in chain * @throws IOException */ public synchronized OServerAdmin dropDatabase( final String iDatabaseName, final String storageType) throws IOException { boolean retry = true; while (retry) { retry = networkAdminOperation( new OStorageRemoteOperation<Boolean>() { @Override public Boolean execute( final OChannelBinaryAsynchClient network, OStorageRemoteSession session) throws IOException { try { try { storage.beginRequest( network, OChannelBinaryProtocol.REQUEST_DB_DROP, session); network.writeString(iDatabaseName); network.writeString(storageType); } finally { storage.endRequest(network); } storage.getResponse(network, session); return false; } catch (OModificationOperationProhibitedException oope) { return handleDBFreeze(); } } }, "Cannot delete the remote storage: " + storage.getName()); } final Set<OStorage> underlyingStorages = new HashSet<OStorage>(); for (OStorage s : Orient.instance().getStorages()) { if (s.getType().equals(storage.getType()) && s.getName().equals(storage.getName())) { underlyingStorages.add(s.getUnderlying()); } } for (OStorage s : underlyingStorages) { s.close(true, true); } ODatabaseRecordThreadLocal.INSTANCE.remove(); return this; }
@Override public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception { checkSyntax(iRequest.url, 1, "Syntax error: server"); iRequest.data.commandInfo = "Server status"; try { StringWriter jsonBuffer = new StringWriter(); OJSONWriter json = new OJSONWriter(jsonBuffer); json.beginObject(); json.beginCollection(1, true, "connections"); String lastCommandOn; String connectedOn; final List<OClientConnection> conns = OClientConnectionManager.instance().getConnections(); for (OClientConnection c : conns) { final ONetworkProtocolData data = c.data; synchronized (dateTimeFormat) { lastCommandOn = dateTimeFormat.format(new Date(data.lastCommandReceived)); connectedOn = dateTimeFormat.format(new Date(c.since)); } json.beginObject(2); writeField(json, 2, "connectionId", c.id); writeField( json, 2, "remoteAddress", c.protocol.getChannel() != null ? c.protocol.getChannel().toString() : "Disconnected"); writeField(json, 2, "db", data.lastDatabase != null ? data.lastDatabase : "-"); writeField(json, 2, "user", data.lastUser != null ? data.lastUser : "******"); writeField(json, 2, "totalRequests", data.totalRequests); writeField(json, 2, "commandInfo", data.commandInfo); writeField(json, 2, "commandDetail", data.commandDetail); writeField(json, 2, "lastCommandOn", lastCommandOn); writeField(json, 2, "lastCommandInfo", data.lastCommandInfo); writeField(json, 2, "lastCommandDetail", data.lastCommandDetail); writeField(json, 2, "lastExecutionTime", data.lastCommandExecutionTime); writeField(json, 2, "totalWorkingTime", data.totalCommandExecutionTime); writeField(json, 2, "connectedOn", connectedOn); writeField(json, 2, "protocol", c.protocol.getType()); writeField(json, 2, "clientId", data.clientId); final StringBuilder driver = new StringBuilder(); if (data.driverName != null) { driver.append(data.driverName); driver.append(" v"); driver.append(data.driverVersion); driver.append(" Protocol v"); driver.append(data.protocolVersion); } writeField(json, 2, "driver", driver.toString()); json.endObject(2); } json.endCollection(1, false); json.beginCollection(1, true, "dbs"); Map<String, OResourcePool<String, ODatabaseDocumentTx>> dbPool = OSharedDocumentDatabase.getDatabasePools(); for (Entry<String, OResourcePool<String, ODatabaseDocumentTx>> entry : dbPool.entrySet()) { for (ODatabaseDocumentTx db : entry.getValue().getResources()) { json.beginObject(2); writeField(json, 2, "db", db.getName()); writeField(json, 2, "user", db.getUser() != null ? db.getUser().getName() : "-"); writeField(json, 2, "status", db.isClosed() ? "closed" : "open"); writeField(json, 2, "type", db.getType()); writeField(json, 2, "storageType", db.getStorage().getType()); json.endObject(2); } } json.endCollection(1, false); json.beginCollection(1, true, "storages"); Collection<OStorage> storages = Orient.instance().getStorages(); for (OStorage s : storages) { json.beginObject(2); writeField(json, 2, "name", s.getName()); writeField(json, 2, "type", s.getClass().getSimpleName()); writeField( json, 2, "path", s instanceof OStorageLocalAbstract ? ((OStorageLocalAbstract) s).getStoragePath().replace('\\', '/') : ""); writeField(json, 2, "activeUsers", s.getUsers()); json.endObject(2); } json.endCollection(1, false); json.beginCollection(2, true, "properties"); for (OServerEntryConfiguration entry : OServerMain.server().getConfiguration().properties) { json.beginObject(3, true, null); json.writeAttribute(4, false, "name", entry.name); json.writeAttribute(4, false, "value", entry.value); json.endObject(3, true); } json.endCollection(2, true); json.endObject(); iResponse.send( OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, jsonBuffer.toString(), null); } finally { } return false; }