Exemplo n.º 1
0
 private void shutdownSamp() {
   sampMonitorHandle.cancel(true);
   sampClient.setActive(false);
   sampClient = null;
   if (hub != null) {
     hub.shutdown();
   }
 }
Exemplo n.º 2
0
 private void startSamp() {
   logger.log(Level.INFO, "Initializing Hub Connector");
   sampClient = new HubConnector(sampClientProfile);
   sampClient.declareMetadata(metadata);
   sampClient.declareSubscriptions(sampClient.computeSubscriptions());
   sampClient.setActive(true);
   Runnable sampMonitor =
       new Runnable() {
         @Override
         public void run() {
           monitorSampOnce();
         }
       };
   if (resourceServer != null) {
     resourceServer.start();
     logger.log(Level.INFO, "Starting SAMP resource server");
   }
   logger.log(Level.INFO, "Starting SAMP monitor thread");
   sampMonitorHandle = executor.scheduleAtFixedRate(sampMonitor, 0, 3, TimeUnit.SECONDS);
 }
Exemplo n.º 3
0
 private void monitorSampOnce() {
   logger.log(LEVEL, "Monitor State: ");
   logger.log(LEVEL, "sampClient.isConnected(): " + sampClient.isConnected());
   logger.log(LEVEL, "sampClientProfile.isHubRunning(): " + sampClientProfile.isHubRunning());
   try {
     logger.log(LEVEL, "sampClient.getConnection(): " + sampClient.getConnection());
   } catch (IOException ex) {
     logger.log(Level.WARNING, "sampClient.getConnection(): exception", ex);
   }
   logger.log(LEVEL, "startingHub: " + startingHub);
   logger.log(LEVEL, "autoRunHub: " + autoRunHub);
   if (!sampClientProfile.isHubRunning() && !startingHub && autoRunHub) {
     logger.log(Level.INFO, "No Hub running, starting one ourselves");
     startingHub = true;
     if (hub != null) {
       logger.log(Level.WARNING, "A hub was found, shutting it down before proceeding");
       hub.shutdown();
     }
     logger.log(Level.INFO, "Starting Hub");
     try {
       hub = Hub.runHub(HubServiceMode.MESSAGE_GUI);
     } catch (IOException e) {
       logger.log(
           Level.WARNING,
           "A hub was found after all, trying to continue without starting our own");
     }
     startingHub = false;
   }
   boolean newState;
   newState = sampClient.isConnected() && sampClientProfile.isHubRunning();
   logger.log(LEVEL, "SAMP client connected: " + newState);
   if (newState != sampUp) {
     logger.log(Level.INFO, "Client connection status changed: " + sampUp + " -> " + newState);
     sampUp = newState;
     logger.log(LEVEL, "Calling connection listeners callbacks");
     for (SAMPConnectionListener listener : sampListeners) {
       listener.run(sampUp);
     }
   }
 }
Exemplo n.º 4
0
  public void sendMessage(SAMPMessage message) throws SampException {
    if (sampClient.getConnection().getSubscribedClients(message.get().getMType()).isEmpty())
      throw new SampException("No clients can receive the SAMP Message");

    sampClient.callAll(message.get(), new LogResultHandler(message.get()), DEFAULT_TIMEOUT);
  }
Exemplo n.º 5
0
 public void addMessageHandler(MessageHandler handler) {
   sampClient.addMessageHandler(handler);
   if (sampClientProfile.isHubRunning()) {
     sampClient.declareSubscriptions(sampClient.computeSubscriptions());
   }
 }