예제 #1
0
  private void stopPublisher(int id) {
    synchronized (runningPublishers) {
      PublisherRT<?> publisher = getRunningPublisher(id);
      if (publisher == null) return;

      publisher.terminate();
      publisher.joinTermination();
      runningPublishers.remove(publisher);
    }
  }
예제 #2
0
  private void startPublisher(PublisherVO<? extends PublishedPointVO> vo) {
    synchronized (runningPublishers) {
      // If the publisher is already running, just quit.
      if (isPublisherRunning(vo.getId())) return;

      // Ensure that the data source is enabled.
      Assert.isTrue(vo.isEnabled());

      // Create and start the runtime version of the publisher.
      PublisherRT<?> publisher = vo.createPublisherRT();
      publisher.initialize();

      // Add it to the list of running publishers.
      runningPublishers.add(publisher);
    }
  }
예제 #3
0
  public synchronized void terminate() {
    if (!started) throw new ShouldNeverHappenException("RuntimeManager not yet started");

    started = false;

    for (PublisherRT<? extends PublishedPointVO> publisher : runningPublishers)
      stopPublisher(publisher.getId());

    // Get the RTM defs and sort by reverse init priority.
    List<RuntimeManagerDefinition> defs =
        ModuleRegistry.getDefinitions(RuntimeManagerDefinition.class);
    Collections.sort(
        defs,
        new Comparator<RuntimeManagerDefinition>() {
          @Override
          public int compare(RuntimeManagerDefinition def1, RuntimeManagerDefinition def2) {
            return def2.getInitializationPriority() - def1.getInitializationPriority();
          }
        });

    // Stop everything with priority up to and including 5.
    int rtmdIndex = stopRTMDefs(defs, 0, 5);

    // Stop data sources in reverse start priority order.
    Map<DataSourceDefinition.StartPriority, List<DataSourceRT>> priorityMap =
        new HashMap<DataSourceDefinition.StartPriority, List<DataSourceRT>>();
    for (DataSourceRT rt : runningDataSources) {
      List<DataSourceRT> priorityList =
          priorityMap.get(rt.getVo().getDefinition().getStartPriority());
      if (priorityList == null) {
        priorityList = new ArrayList<DataSourceRT>();
        priorityMap.put(rt.getVo().getDefinition().getStartPriority(), priorityList);
      }
      priorityList.add(rt);
    }

    DataSourceDefinition.StartPriority[] priorities = DataSourceDefinition.StartPriority.values();
    for (int i = priorities.length - 1; i >= 0; i--) {
      List<DataSourceRT> priorityList = priorityMap.get(priorities[i]);
      if (priorityList != null) {
        for (DataSourceRT rt : priorityList) stopDataSource(rt.getId());
      }
    }

    // Run everything else.
    rtmdIndex = stopRTMDefs(defs, rtmdIndex, Integer.MIN_VALUE);
  }
예제 #4
0
 protected void pointInitialized(PublishedPointRT<SquwkPointVO> rt) {
   super.pointInitialized(rt);
   String guid;
   if (this.squwkClient != null) {
     guid = ((SquwkPointVO) rt.getVo()).getGuid();
     for (Point point : this.squwkPoints)
       if (point.getGuid().equals(guid)) {
         ((SquwkPointVO) rt.getVo()).setDataType(point.getDataType());
         break;
       }
   }
 }
예제 #5
0
 public void initialize() {
   super.initialize(new SquwkSendThread());
   try {
     this.squwkPoints = ((List) this.squwkClient.send(new PointListRequest()));
   } catch (SquwkException e) {
     LOG.warn("Request exception", e);
     Common.eventManager.raiseEvent(
         this.requestExceptionEventType,
         System.currentTimeMillis(),
         true,
         2,
         toTranslatableMessage(e),
         createEventContext());
   }
 }
예제 #6
0
 //
 //
 // Publishers
 //
 public PublisherRT<?> getRunningPublisher(int publisherId) {
   for (PublisherRT<?> publisher : runningPublishers) {
     if (publisher.getId() == publisherId) return publisher;
   }
   return null;
 }