Пример #1
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);
     }
   }
 }
Пример #2
0
 public void addMessageHandler(MessageHandler handler) {
   sampClient.addMessageHandler(handler);
   if (sampClientProfile.isHubRunning()) {
     sampClient.declareSubscriptions(sampClient.computeSubscriptions());
   }
 }