protected <T> T networkAdminOperation( final OStorageRemoteOperation<T> operation, final String errorMessage) { OChannelBinaryAsynchClient network = null; try { // TODO:replace this api with one that get connection for only the specified url. String serverUrl = storage.getNextAvailableServerURL(false, session); do { try { network = storage.getNetwork(serverUrl); } catch (OException e) { serverUrl = storage.useNewServerURL(serverUrl); if (serverUrl == null) throw e; } } while (network == null); T res = operation.execute(network, storage.getCurrentSession()); storage.connectionManager.release(network); return res; } catch (Exception e) { if (network != null) storage.connectionManager.release(network); storage.close(true, false); throw OException.wrapException(new OStorageException(errorMessage), e); } }