ClientRequest removePersistentRebootRequest(boolean global, String identifier)
     throws MessageInvalidException {
   FCPClient client = global ? server.globalRebootClient : getRebootClient();
   ClientRequest req = client.getRequest(identifier, null);
   if (req != null) {
     client.removeByIdentifier(identifier, true, server, null, server.core.clientContext);
   }
   return req;
 }
 ClientRequest removePersistentForeverRequest(
     boolean global, String identifier, ObjectContainer container) throws MessageInvalidException {
   FCPClient client = global ? server.globalForeverClient : getForeverClient(container);
   container.activate(client, 1);
   ClientRequest req = client.getRequest(identifier, container);
   if (req != null) {
     client.removeByIdentifier(identifier, true, server, container, server.core.clientContext);
   }
   if (!global) container.deactivate(client, 1);
   return req;
 }
  public void close() {
    ClientRequest[] requests;
    if (rebootClient != null) rebootClient.onLostConnection(this);
    if (foreverClient != null) foreverClient.onLostConnection(this);
    boolean dupe;
    SubscribeUSK[] uskSubscriptions2;
    synchronized (this) {
      if (isClosed) {
        Logger.error(this, "Already closed: " + this, new Exception("debug"));
        return;
      }
      isClosed = true;
      requests = new ClientRequest[requestsByIdentifier.size()];
      requests = requestsByIdentifier.values().toArray(requests);
      requestsByIdentifier.clear();
      uskSubscriptions2 =
          uskSubscriptions.values().toArray(new SubscribeUSK[uskSubscriptions.size()]);
      dupe = killedDupe;
    }
    for (ClientRequest req : requests) req.onLostConnection(null, server.core.clientContext);
    for (SubscribeUSK sub : uskSubscriptions2) sub.unsubscribe();
    if (!dupe) {
      try {
        server.core.clientContext.jobRunner.queue(
            new DBJob() {

              public boolean run(ObjectContainer container, ClientContext context) {
                if ((rebootClient != null) && !rebootClient.hasPersistentRequests(null))
                  server.unregisterClient(rebootClient, null);
                if (foreverClient != null) {
                  if (!container.ext().isStored(foreverClient)) {
                    Logger.normal(
                        this,
                        "foreverClient is not stored in the database in lost connection non-dupe callback; not deleting it");
                    return false;
                  }
                  container.activate(foreverClient, 1);
                  if (!foreverClient.hasPersistentRequests(container))
                    server.unregisterClient(foreverClient, container);
                  container.deactivate(foreverClient, 1);
                }
                return false;
              }
            },
            NativeThread.NORM_PRIORITY,
            false);
      } catch (DatabaseDisabledException e) {
        // Ignore
      }
    }

    outputHandler.onClosed();
  }
 protected FCPClient createForeverClient(String name, ObjectContainer container) {
   synchronized (FCPConnectionHandler.this) {
     if (foreverClient != null) return foreverClient;
   }
   FCPClient client =
       server.registerForeverClient(name, server.core, FCPConnectionHandler.this, container);
   synchronized (FCPConnectionHandler.this) {
     foreverClient = client;
     FCPConnectionHandler.this.notifyAll();
   }
   client.queuePendingMessagesOnConnectionRestartAsync(
       outputHandler, container, server.core.clientContext);
   return foreverClient;
 }
 public void setClientName(final String name) {
   this.clientName = name;
   rebootClient = server.registerRebootClient(name, server.core, this);
   rebootClient.queuePendingMessagesOnConnectionRestartAsync(
       outputHandler, null, server.core.clientContext);
   // Create foreverClient lazily. Everything that needs it (especially creating ClientGet's etc)
   // runs on a database job.
   if (logMINOR) Logger.minor(this, "Set client name: " + name);
 }
 public FCPClient getForeverClient(ObjectContainer container) {
   synchronized (this) {
     if (foreverClient == null) {
       foreverClient = createForeverClient(clientName, container);
     }
     container.activate(foreverClient, 1);
     foreverClient.init(container);
     return foreverClient;
   }
 }