Package agentj.thread

Examples of agentj.thread.Controller


    public static void sleep(long millis) throws InterruptedException {
        logger.trace("Entering");


        Controller cont = AgentJVirtualMachine.getCurrentNS2NodeController();

        ProtolibTimer timer = new ProtolibTimer(cont, (double)millis /1000.0, 0);

        // set up the controller to be the socket listener
View Full Code Here


    static Logger logger = Log.getLogger(StaticObject.class);

    public static final void wait(java.lang.Object callingObject) throws InterruptedException {
        logger.debug("Entering");
        Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();
        logger.trace("Wait wait() on Node " + controller.getLocalHost() );
        logger.trace("Calling Object = " + callingObject.getClass().getName());

        java.lang.Thread awaitThread = Thread.currentThread();

        String threadName = awaitThread.getClass().getName();

        // keep all logic in the created WaitInvocation to keep thread safety here and
        // remove the need for more locks
        WaitInvocation waitObj = new WaitInvocation(controller);

        ObjectCounter objctr = getObject(callingObject);
        if (objctr!=null) {
            objctr.increment();
        } else {
            logger.trace("Adding a new object to Vector for " + callingObject.getClass().getName());           
            ObjectCounter ob=new ObjectCounter(1,callingObject);
            objectsWaiting.add(ob);
        }

        Logging.monitorStatus(controller, Logging.MonitorStatusType.WAIT, threadName);
        controller.getThreadMonitor().threadPaused(threadName); // we are stopping ...

        waitObj.agentJWait(callingObject); // returns when done ...

        Logging.monitorStatus(controller, Logging.MonitorStatusType.RELEASED, threadName);
        controller.getThreadMonitor().threadContinued(threadName); // we are stopping ...
        synchronized (callingObject) {
        callingObject.notify(); // to release notify method ....
        }
//        ProtolibTimer timer = new ProtolibTimer(controller, 0, 0);
        //       timer.startTimerAndBlockUntilTimeout(); // and stopping
View Full Code Here

        logger.debug("Leaving");
    }

    public static final void wait(java.lang.Object callingObject, long millis) throws InterruptedException {
        logger.debug("Entering");
        Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();
        logger.trace("Wait wait("+millis+") on Node " + controller.getLocalHost() );
        logger.trace("Calling Object = " + callingObject.getClass().getName());

        java.lang.Thread awaitThread = Thread.currentThread();
        String threadName = awaitThread.getClass().getName();

        // keep all logic in the created WaitInvocation to keep thread safety here and
        // remove the need for more locks
        WaitInvocation waitObj = new WaitInvocation(controller);

        ObjectCounter objctr = getObject(callingObject);
        if (objctr!=null) {
            objctr.increment();
        } else {
            logger.trace("Adding a new object to Vector for " + callingObject.getClass().getName());
            ObjectCounter ob=new ObjectCounter(1,callingObject);
            ob.setWaitInvocationObject(waitObj);
            objectsWaiting.add(ob);
        }
        // kick off timer first...
        waitObj.kickOffWaitTimer(millis);

        Logging.monitorStatus(controller, Logging.MonitorStatusType.WAIT, threadName);
        controller.getThreadMonitor().threadPaused(threadName); // we are stopping ...
        waitObj.agentJWait(callingObject); // returns when done ...

        Logging.monitorStatus(controller, Logging.MonitorStatusType.RELEASED, threadName);
      //  if (!waitObj.getWasTimedOut())
        controller.getThreadMonitor().threadContinued(threadName); // timed out objects already have added one to threadcount
        synchronized(callingObject) {
        callingObject.notify(); // to release notify method ....
        }
//       ProtolibTimer timer = new ProtolibTimer(controller, 0, 0);
//       timer.startTimerAndBlockUntilTimeout(); // and stopping
View Full Code Here

        logger.debug("Leaving");
     }

    public final static void notify(java.lang.Object callingObject) {
        logger.debug("Entering");
         Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();
         Thread waitThread = Thread.currentThread();
         String threadName = waitThread.getClass().getName();

         ObjectCounter objctr = getObject(callingObject);
         if (objctr!=null) {
View Full Code Here

        logger.debug("Exiting");
    }

    public static final void notifyAll(java.lang.Object callingObject) {
        logger.debug("Entering");
        Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();
        Thread waitThread = Thread.currentThread();
        String threadName = waitThread.getClass().getName();
        ObjectCounter objctr = getObject(callingObject);
        if ((objctr!=null) && (objctr.getObjectsWaiting()!=0)) {
            logger.debug("NotifyAll: check ok, object waiting");
View Full Code Here

     * this operation has no effect.
     */
    public static void unpark(Thread thread) {
        if (thread != null)
            getUnsafe().unpark(thread);
        Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();
        Thread threadparking=Thread.currentThread();
        String threadName=threadparking.getClass().getName();
        Logging.parkStatus(controller, Logging.ParkStatusType.UNPARK, threadName);
        controller.getThreadMonitor().threadContinued(threadName); // to sync up with await...
    }
View Full Code Here

     * method to return. Callers should re-check the conditions which caused
     * the thread to park in the first place. Callers may also determine,
     * for example, the interrupt status of the thread upon return.
     */
    public static void park() {
        Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();

        Thread threadparking=Thread.currentThread();
        String threadparkingName=threadparking.getClass().getName();

        logger.debug("Trying park on Thread =  " + threadparking);
        Logging.parkStatus(controller, Logging.ParkStatusType.PARK, threadparkingName);
        controller.getThreadMonitor().threadPaused(threadparkingName); // we are stopping ...
        getUnsafe().park(false, 0L);

        Logging.parkStatus(controller, Logging.ParkStatusType.PARKRELEASED, threadparkingName);

        // Wait for ns-2
        ProtolibTimer timer = new ProtolibTimer(controller, 0, 0); // and then immediately stopping
        timer.startTimerAndBlockUntilTimeout(); // and then starting again once timer has returned
        // timer does the release needed for the unpark handshake.

        AgentJVirtualMachine.setCurrentNode(controller.getNs2node());
        // carry on now since we have woken up ns-2
    }
View Full Code Here

     * @param nanos the maximum number of nanoseconds to wait
     */
    public static void parkNanos(long nanos) {
        if (nanos <= 0) return;

        Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();
        Thread threadparking=Thread.currentThread();
        String threadparkingName=threadparking.getClass().getName();

        logger.debug("Trying park on Thread =  " + threadparking);
        Logging.parkStatus(controller, Logging.ParkStatusType.PARK, threadparkingName);
        controller.getThreadMonitor().threadPaused(threadparkingName); // we are stopping ...

        // keep all logic in the created awaitObject, to keep thread safety here and
        // remove the need for more locks
        ParkTimeout parkObj = new ParkTimeout(controller, threadparking);

        parkObj.parkNanos(nanos); // returns when done ...

        Logging.parkStatus(controller, Logging.ParkStatusType.PARKRELEASED, threadparkingName);

        // Wait for ns-2
        ProtolibTimer timer = new ProtolibTimer(controller, 0, 0); // and then immediately stopping
        timer.startTimerAndBlockUntilTimeout(); // and then starting again once timer has returned
        // timer does the release needed for the unpark handshake.

        AgentJVirtualMachine.setCurrentNode(controller.getNs2node());
        // carry on now since we have woken up ns-2
    }
View Full Code Here

     *
     * @param deadline the absolute time, in milliseconds from the Epoch, to
     * wait until
     */
    public static void parkUntil(long deadline) {
        Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();
        Thread threadparking=Thread.currentThread();
        String threadparkingName=threadparking.getClass().getName();

        logger.debug("Trying park on Thread =  " + threadparking);
        Logging.parkStatus(controller, Logging.ParkStatusType.PARK, threadparkingName);
        controller.getThreadMonitor().threadPaused(threadparkingName); // we are stopping ...

        // keep all logic in the created awaitObject, to keep thread safety here and
        // remove the need for more locks
        ParkTimeout parkObj = new ParkTimeout(controller, threadparking);

        parkObj.parkUntil(deadline); // returns when done ...

        Logging.parkStatus(controller, Logging.ParkStatusType.PARKRELEASED, threadparkingName);

        // Wait for ns-2
        ProtolibTimer timer = new ProtolibTimer(controller, 0, 0); // and then immediately stopping
        timer.startTimerAndBlockUntilTimeout(); // and then starting again once timer has returned
        // timer does the release needed for the unpark handshake.

        AgentJVirtualMachine.setCurrentNode(controller.getNs2node());
        // carry on now since we have woken up ns-2
    }
View Full Code Here

        logger.trace("javm/util/TimerTask: I have been cancelled -- timeOut left");
              timer.removeTimerTask(this);
        return;
   }

       Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();
       run();
   logger.trace("TimerTask.java: run() left");

   if (period != 0){
        logger.trace("javm/util/TimerTask: new Timer created");
View Full Code Here

TOP

Related Classes of agentj.thread.Controller

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.