@Override
 public Boolean delete() {
   if (name != null && !name.isEmpty()) {
     try {
       if (cascading && !isReaping()) {
         Reaper reaper = ReaperFactory.getReaper(this);
         if (reaper != null) {
           setReaping(true);
           reaper.reap();
         }
       }
       deleteThis();
       return true;
     } catch (KubernetesClientException e) {
       if (e.getCode() != 404) {
         throw e;
       }
       return false;
     }
   } else {
     try {
       deleteList();
       return true;
     } catch (KubernetesClientException e) {
       if (e.getCode() != 404) {
         throw e;
       }
       return false;
     }
   }
 }
  public void start() {
    // Start the background reaper thread
    if (reaper == null) {
      reaper = new Reaper("Expirer");
      reaper.addCallback(this, checkInterval * 1000);
    }

    reaper.startReaper();
  }
 public void clear(IndexShard shard) {
   if (shard == null) {
     return;
   }
   keysToClean.add(new CleanupKey(shard, -1));
   logger.trace("{} explicit cache clear", shard.shardId());
   reaper.reap();
 }
Beispiel #4
0
 @JRubyMethod(name = "close!", visibility = PUBLIC)
 public IRubyObject close_bang(ThreadContext context) {
   referenceSet.remove(reaper);
   reaper.released = true;
   _close(context);
   tmpFile.delete();
   return context.getRuntime().getNil();
 }
Beispiel #5
0
 @JRubyMethod(name = {"unlink", "delete"})
 public IRubyObject unlink(ThreadContext context) {
   if (!tmpFile.exists() || tmpFile.delete()) {
     referenceSet.remove(reaper);
     reaper.released = true;
     path = null;
   }
   return context.getRuntime().getNil();
 }
Beispiel #6
0
  private void destroy() throws IOException {
    for (IOThread it : ioThreads) {
      it.stop();
    }
    for (IOThread it : ioThreads) {
      it.close();
    }

    if (reaper != null) {
      reaper.close();
    }
    termMailbox.close();

    tag = 0xdeadbeef;
  }
 public void stop() {
   if (reaper != null) {
     reaper.stop();
   }
   lock.lock();
   try {
     for (Iterator<Entry<Address, V>> i = conns.entrySet().iterator(); i.hasNext(); ) {
       Entry<Address, V> e = i.next();
       Util.close(e.getValue());
     }
     clear();
   } finally {
     lock.unlock();
   }
   conn_listeners.clear();
 }
Beispiel #8
0
  public void terminate() {
    tag = 0xdeadbeef;

    if (!starting.get()) {
      slotSync.lock();
      try {
        //  Check whether termination was already underway, but interrupted and now
        //  restarted.
        boolean restarted = terminating;
        terminating = true;

        //  First attempt to terminate the context.
        if (!restarted) {
          //  First send stop command to sockets so that any blocking calls
          //  can be interrupted. If there are no sockets we can ask reaper
          //  thread to stop.
          for (SocketBase socket : sockets) {
            socket.stop();
          }
          if (sockets.isEmpty()) {
            reaper.stop();
          }
        }
      } finally {
        slotSync.unlock();
      }
      //  Wait till reaper thread closes all the sockets.
      Command cmd = termMailbox.recv(-1);
      if (cmd == null) {
        throw new IllegalStateException();
      }
      assert (cmd.type() == Command.Type.DONE);
      slotSync.lock();
      try {
        assert (sockets.isEmpty());
      } finally {
        slotSync.unlock();
      }
    }

    //  Deallocate the resources.
    try {
      destroy();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
Beispiel #9
0
  public void destroySocket(SocketBase socket) {
    slotSync.lock();

    //  Free the associated thread slot.
    try {
      int tid = socket.getTid();
      emptySlots.add(tid);
      slots[tid] = null;

      //  Remove the socket from the list of sockets.
      sockets.remove(socket);

      //  If zmq_term() was already called and there are no more socket
      //  we can ask reaper thread to terminate.
      if (terminating && sockets.isEmpty()) {
        reaper.stop();
      }
    } finally {
      slotSync.unlock();
    }
  }
 public void start() throws Exception {
   if (reaper != null) {
     reaper.start();
   }
 }
Beispiel #11
0
  public SocketBase createSocket(int type) {
    SocketBase s = null;
    slotSync.lock();
    try {
      if (starting.compareAndSet(true, false)) {
        //  Initialize the array of mailboxes. Additional three slots are for
        //  zmq_term thread and reaper thread.
        int mazmq;
        int ios;
        optSync.lock();
        try {
          mazmq = maxSockets;
          ios = ioThreadCount;
        } finally {
          optSync.unlock();
        }
        slotCount = mazmq + ios + 2;
        slots = new Mailbox[slotCount];
        // alloc_assert (slots);

        //  Initialize the infrastructure for zmq_term thread.
        slots[TERM_TID] = termMailbox;

        //  Create the reaper thread.
        reaper = new Reaper(this, REAPER_TID);
        // alloc_assert (reaper);
        slots[REAPER_TID] = reaper.getMailbox();
        reaper.start();

        //  Create I/O thread objects and launch them.
        for (int i = 2; i != ios + 2; i++) {
          IOThread ioThread = new IOThread(this, i);
          // alloc_assert (io_thread);
          ioThreads.add(ioThread);
          slots[i] = ioThread.getMailbox();
          ioThread.start();
        }

        //  In the unused part of the slot array, create a list of empty slots.
        for (int i = (int) slotCount - 1; i >= (int) ios + 2; i--) {
          emptySlots.add(i);
          slots[i] = null;
        }
      }

      //  Once zmq_term() was called, we can't create new sockets.
      if (terminating) {
        throw new ZError.CtxTerminatedException();
      }

      //  If maxSockets limit was reached, return error.
      if (emptySlots.isEmpty()) {
        throw new IllegalStateException("EMFILE");
      }

      //  Choose a slot for the socket.
      int slot = emptySlots.pollLast();

      //  Generate new unique socket ID.
      int sid = maxSocketId.incrementAndGet();

      //  Create the socket and register its mailbox.
      s = SocketBase.create(type, this, slot, sid);
      if (s == null) {
        emptySlots.addLast(slot);
        return null;
      }
      sockets.add(s);
      slots[slot] = s.getMailbox();
    } finally {
      slotSync.unlock();
    }

    return s;
  }
 public void close() {
   reaper.close();
   cache.invalidateAll();
 }
Beispiel #13
0
 public void stop() {
   reaper.stopReaper();
 }