示例#1
0
文件: UDP.java 项目: NZDIS/jgroups
  /** Stops unicast and multicast receiver threads */
  void stopThreads() {
    Thread tmp;

    // 1. Stop the multicast receiver thread
    if (mcast_receiver != null) {
      if (mcast_receiver.isAlive()) {
        tmp = mcast_receiver;
        mcast_receiver = null;
        closeMulticastSocket(); // will cause the multicast thread to terminate
        tmp.interrupt();
        try {
          tmp.join(100);
        } catch (Exception e) {
        }
        tmp = null;
      }
      mcast_receiver = null;
    }

    // 2. Stop the unicast receiver thread
    if (ucast_receiver != null) {
      ucast_receiver.stop();
      ucast_receiver = null;
    }

    // 3. Stop the in_packet_handler thread
    if (incoming_packet_handler != null) {
      incoming_packet_handler.stop();
    }
  }
示例#2
0
  private void startListening() {
    // if listener thread is alive and listening now, no need to recreate. Just reuse it.
    if (listenerThread != null && listenerThread.isAlive()) {
      return;
    }

    Runnable listeningAction =
        () -> {
          boolean running = true;
          while (connected && running) {
            List<String> list = getMessages();

            localHistory.addAll(list);

            try {
              Thread.sleep(POLLING_PERIOD_MILLIS);
            } catch (InterruptedException e) {
              logger.error("The message listening thread was interrupted", e);
              running = false;
            }
          }
        };
    listenerThread = new Thread(listeningAction);
    listenerThread.start();
  }
示例#3
0
 private void startReceiver() {
   if (receiver == null || !receiver.isAlive()) {
     receiver = new Thread(Util.getGlobalThreadGroup(), this, "ReceiverThread");
     receiver.setDaemon(true);
     receiver.start();
     if (log.isTraceEnabled()) log.trace("receiver thread started");
   }
 }
示例#4
0
文件: IPCapture.java 项目: star003/sb
 public void start() {
   if (streamReader != null && streamReader.isAlive()) {
     System.out.println("Camera already started");
     return;
   }
   streamReader = new Thread(this, "HTTP Stream reader");
   keepAlive = true;
   streamReader.start();
 }
示例#5
0
 public synchronized void handle(Socket socket) throws IOException {
   con = new Connection(socket);
   count = 0;
   if (thread == null || !thread.isAlive()) {
     thread = new Thread(runners, this);
     thread.start();
   } else {
     notify();
   }
 }
示例#6
0
文件: UDP.java 项目: NZDIS/jgroups
 public void stop() {
   Thread tmp;
   if (thread != null && thread.isAlive()) {
     running = false;
     tmp = thread;
     thread = null;
     closeSocket(); // this will cause the thread to break out of its loop
     tmp.interrupt();
     tmp = null;
   }
   thread = null;
 }
示例#7
0
文件: IPCapture.java 项目: star003/sb
 public void stop() {
   if (streamReader == null || !streamReader.isAlive()) {
     System.out.println("Camera already stopped");
     return;
   }
   keepAlive = false;
   try {
     streamReader.join();
   } catch (InterruptedException e) {
     System.err.println(e.getMessage());
   }
 }
示例#8
0
  public static void startChat(Socket socket) {

    InputStream input;
    DataInputStream dis = null;
    OutputStream output;
    DataOutputStream dos = null;

    try {
      input = socket.getInputStream();
      dis = new DataInputStream(input);
      output = socket.getOutputStream();
      dos = new DataOutputStream(output);

      dos.writeInt(3); // send 5 as request to server to request for chat
    } catch (IOException e) {
      System.out.println("Cannot send requests to server.");
    }

    System.out.println("Enter your message and hit enter to send.\n");

    connectedToChat = true;

    Thread readThread = new Thread(new Read(dis));
    Thread writeThread = new Thread(new Write(dos));
    readThread.start();
    writeThread.start();

    while ((writeThread.isAlive()) && (readThread.isAlive())) {}

    System.out.println("Disconnected from chat. Enter anything to return to menu.");

    if (!writeThread.isAlive()) {
      Scanner scanner = new Scanner(System.in);
      scanner.next();
    }

    while (writeThread.isAlive()) {}
  }
示例#9
0
  private void startMessageSending() {
    // if listener thread is alive and listening now, no need to recreate. Just reuse it.
    if (messageSendingThread != null && messageSendingThread.isAlive()) {
      return;
    }

    Runnable messageSendingAction =
        () -> {
          Scanner scanner = new Scanner(System.in);
          while (connected) {
            String message = scanner.nextLine();
            sendMessage(message);
          }
        };
    messageSendingThread = new Thread(messageSendingAction);
    messageSendingThread.start();
  }
示例#10
0
文件: UDP.java 项目: NZDIS/jgroups
  /** Starts the unicast and multicast receiver threads */
  void startThreads() throws Exception {
    if (ucast_receiver == null) {
      // start the listener thread of the ucast_recv_sock
      ucast_receiver = new UcastReceiver();
      ucast_receiver.start();
      if (Trace.trace) {
        Trace.info("UDP.startThreads()", "created unicast receiver thread");
      }
    }

    if (ip_mcast) {
      if (mcast_receiver != null) {
        if (mcast_receiver.isAlive()) {
          if (Trace.trace) {
            Trace.info(
                "UDP.createThreads()",
                "did not create new multicastreceiver thread as existing "
                    + "multicast receiver thread is still running");
          }
        } else {
          mcast_receiver = null; // will be created just below...
        }
      }

      if (mcast_receiver == null) {
        mcast_receiver = new Thread(this, "UDP mcast receiver");
        mcast_receiver.setPriority(Thread.MAX_PRIORITY); // needed ????
        mcast_receiver.setDaemon(true);
        mcast_receiver.start();
      }
    }
    if (use_outgoing_packet_handler) {
      outgoing_packet_handler.start();
    }
    if (use_incoming_packet_handler) {
      incoming_packet_handler.start();
    }
  }
示例#11
0
 /**
  * Returns true if the server is ready to accept new clients.
  *
  * @return true if the server is listening.
  */
 public final boolean isListening() {
   return connectionListener != null && connectionListener.isAlive(); // modified in version 2.31
 }
示例#12
0
文件: IPCapture.java 项目: star003/sb
 public boolean isAlive() {
   return streamReader.isAlive();
 }