Package org.nebulaframework.grid.service.event

Examples of org.nebulaframework.grid.service.event.ServiceHookCallback


    this.trackers.put(nodeId, tracker);
   
    tracker.start();
   
    //Add ServiceHook to auto remove node when disconnected
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
      public void onServiceEvent(ServiceMessage message) {
        removeNode(nodeId);
      }
    },nodeId.toString(),ServiceMessageType.NODE_UNREGISTERED, ServiceMessageType.HEARTBEAT_FAILED );
  }
View Full Code Here


    // Notify Service Event
    ServiceMessage message = new ServiceMessage(nodeId.toString(),ServiceMessageType.NODE_REGISTERED);
    ServiceEventsSupport.getInstance().onServiceMessage(message);

    // Create HeartBeat Failure Hook
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
      public void onServiceEvent(ServiceMessage msg) {
        synchronized (this) {
          clusterNodes.remove(nodeId);
         
          // Notify Service Event
View Full Code Here

   * @param instance GridNode instance
   */
  private void registerHooks(GridNode instance) {
   
    // Disconnection Hook
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

      @Override
      public void onServiceEvent(ServiceMessage message) {
        SwingUtilities.invokeLater(new Runnable() {

          @Override
          public void run() {
            updateGridInfo();
          }
         
        });
      }
     
    }, instance.getClusterId().toString(), ServiceMessageType.NODE_DISCONNECTED);
   
    // Job Start Hook
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

      @Override
      public void onServiceEvent(ServiceMessage message) {
       
        final String jobId = message.getMessage();
        final String jobName = GridNode.getInstance()
                  .getJobExecutionService()
                  .getJobName(jobId);
       
        activeJobId = jobId;
       
        final long timeStart = System.currentTimeMillis();
       
        SwingUtilities.invokeLater(new Runnable() {

          @Override
          public void run() {
           
            showBusyIcon();
            setStatus("Executing Job");
           
            ((JLabel) getUIElement("general.stats.jobname"))
                .setText(jobName);

            ((JLabel) getUIElement("general.stats.tasks")).setText("0");
            ((JLabel) getUIElement("general.stats.failures")).setText("0");           
          }
         
        });
       
       
        // Duration Update Thread
        new Thread(new Runnable() {

          @Override
          public void run() {
           
           
           
            while (jobId.equals(activeJobId)) {
             
              SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                  ((JLabel) getUIElement("general.stats.duration"))
                    .setText(TimeUtils.timeDifference(timeStart));
                }
               
              });
             
              try {
                Thread.sleep(1000);
              } catch (InterruptedException e) {
                log.warn("Interrupted", e);
              }
             
            }
          }
         
        }).start();
       
        // Job End Hook
        ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

          @Override
          public void onServiceEvent(ServiceMessage message) {
           
            activeJobId = null;
           
            SwingUtilities.invokeLater(new Runnable() {

              @Override
              public void run() {
               
                try {
                 
                  JLabel durationLabel = getUIElement("general.stats.duration");
                  JLabel jobnameLabel = getUIElement("general.stats.jobname");
                  JLabel tasksLabel = getUIElement("general.stats.tasks");
                  JLabel failuresLabel = getUIElement("general.stats.failures");
                  JLabel totalJobsLabel = getUIElement("general.stats.totaljobs");
                 
                  int tasks = Integer.parseInt(tasksLabel.getText());
                  int failures = Integer.parseInt(failuresLabel.getText());
                 
                 
                  // Create and enter Job History Element
                  JobHistoryElement element =
                      new JobHistoryElement(jobName,
                                            jobId,
                                            TimeUtils.formatDate(timeStart),
                                            durationLabel.getText(),
                                            tasks,
                                            failures);
                 
                  historyList.addJobHistoryElement(element);
                 
                  // Update Job Info Fields
                  durationLabel.setText("N/A");
                  jobnameLabel.setText("N/A");
                  tasksLabel.setText("N/A");
                  failuresLabel.setText("N/A");
                 
                  // Update Total Jobs Count
                  int totalJobs = Integer.parseInt(totalJobsLabel.getText()) + 1;
                  totalJobsLabel.setText(String.valueOf(totalJobs));
                 
                  showIdleIcon();
                  setStatus("Idle");
                 
                } catch (Exception e) {
                  log.warn("[UI] Exception ",e);
                }
               
               
              }
             
            });
          }
         
        }, jobId, ServiceMessageType.LOCAL_JOBFINISHED);
      }
     
    }, ServiceMessageType.LOCAL_JOBSTARTED);
   

    // Task Executed Hook
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

      public void onServiceEvent(final ServiceMessage message) {
       
        SwingUtilities.invokeLater(new Runnable() {

          public void run() {
           
            try {
              // Total Tasks
              JLabel totalTasksLabel = getUIElement("general.stats.totaltasks");
              int totalTasks = Integer.parseInt(totalTasksLabel.getText()) + 1
              totalTasksLabel.setText(String.valueOf(totalTasks));
             
              // If active job, update task count
              if (message.getMessage().equals(activeJobId)) {
                JLabel tasksLabel = getUIElement("general.stats.tasks");
                int tasks = Integer.parseInt(tasksLabel.getText()) + 1
                tasksLabel.setText(String.valueOf(tasks));   
              }
            } catch (Exception e) {
              log.warn("[UI] Exception ",e);
            }
          }
        });
      }
     
    }, ServiceMessageType.LOCAL_TASKDONE);
   
    // Task Failed Hook
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

      public void onServiceEvent(final ServiceMessage message) {
       
        SwingUtilities.invokeLater(new Runnable() {

          public void run() {
           
            try {
              // If active job, update task count
              if (message.getMessage().equals(activeJobId)) {
                JLabel failuresLabel = getUIElement("general.stats.failures");
                int fails = Integer.parseInt(failuresLabel.getText()) + 1
                failuresLabel.setText(String.valueOf(fails));   
              }
            } catch (Exception e) {
              log.warn("[UI] Exception ",e);
            }
          }
        });
      }
    }, ServiceMessageType.LOCAL_TASKFAILED);
   
    // Task Execution Time Hook
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

      public void onServiceEvent(final ServiceMessage message) {
       
        try {
          executionTime += Long.parseLong(message.getMessage());
        } catch (Exception e) {
          log.warn("[UI] Exception ",e);
        }

        SwingUtilities.invokeLater(new Runnable() {

          public void run() {
              updateExecutionTime();
          }
        });
      }
    }, ServiceMessageType.LOCAL_TASKEXEC);
   
    // Node Banned Hook
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

      public void onServiceEvent(final ServiceMessage message) {
       
        // If not relevant to node, ignore
        if (!message.getMessage().startsWith(GridNode.getInstance().getId().toString())) {
View Full Code Here

        // Fire Local Event
        ServiceMessage message = new ServiceMessage(jobId, ServiceMessageType.LOCAL_JOBSTARTED);
        ServiceEventsSupport.fireServiceEvent(message);
       
        // Add a hook to stop job if Cluster fails
        ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

          @Override
          public void onServiceEvent(ServiceMessage message) {
            ServiceMessage msg = new ServiceMessage(jobId, ServiceMessageType.JOB_END);
            try {
View Full Code Here

   
    final GridJobTaskTracker instance = new GridJobTaskTracker(profile, executionManager);
   
   
    // Create Job-End Cleanup Hook
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

      @Override
      public void onServiceEvent(ServiceMessage message) {
        instance.stop();
      }
View Full Code Here

      // Add Collector
      collectors.put(jobId, collector);

      // Create Removal Hook
      ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

        @Override
        public void onServiceEvent(ServiceMessage message) {
          collectors.remove(jobId);
        }
View Full Code Here

      return false;
    }
    workerNodes.add(nodeProfile.getId());
   
    // Add Node Failure Hook to remove workers
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

      @Override
      public void onServiceEvent(ServiceMessage message) {
        workerNodes.remove(UUID.fromString(message.getMessage()));
      }
View Full Code Here

          UnboundedJobProcessor processor = new UnboundedJobProcessor(profile);
          processors.put(profile.getJobId(), processor);
         
         
          // Add Service Hook to Remove Processor When Done
          ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

            @Override
            public void onServiceEvent(ServiceMessage message) {
              // Remove Processor
              processors.remove(profile.getJobId());
View Full Code Here

   *            {@code GridJob} Id
   */
  private void stopIfNodeFails(UUID nodeId, final String jobId) {

    ServiceEventsSupport.addServiceHook(
      new ServiceHookCallback() {
        public void onServiceEvent(
            ServiceMessage message) {
          try {
            cancelJob(jobId);
          } catch (IllegalArgumentException e) {
View Full Code Here

   
    setupTrayIcon(this);
   
   
    // Create Job Start Hook
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
      public void onServiceEvent(final ServiceMessage message) {
        createJobTab(message.getMessage());
      }
    },ServiceMessageType.JOB_START);
  }
View Full Code Here

TOP

Related Classes of org.nebulaframework.grid.service.event.ServiceHookCallback

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.