コード例 #1
0
 /** Closes all open sockets and stops the internal server thread that processes messages. */
 public void close() {
   ServerThread st = server;
   if (st != null) {
     st.close();
     try {
       st.join();
     } catch (InterruptedException ex) {
       logger.warn(ex);
     }
     server = null;
     for (Iterator it = sockets.values().iterator(); it.hasNext(); ) {
       SocketEntry entry = (SocketEntry) it.next();
       try {
         synchronized (entry) {
           entry.getSocket().close();
         }
         logger.debug("Socket to " + entry.getPeerAddress() + " closed");
       } catch (IOException iox) {
         // ingore
         logger.debug(iox);
       }
     }
     if (socketCleaner != null) {
       socketCleaner.cancel();
     }
     socketCleaner = null;
   }
 }
コード例 #2
0
 public void close() {
   stop = true;
   ServerThread st = server;
   if (st != null) {
     st.interrupt();
   }
 }
コード例 #3
0
 /**
  * Returns the name of the listen thread.
  *
  * @return the thread name if in listening mode, otherwise <code>null</code>.
  * @since 1.6
  */
 public String getThreadName() {
   ServerThread st = server;
   if (st != null) {
     return st.getName();
   } else {
     return null;
   }
 }
コード例 #4
0
 /**
  * Returns the priority of the internal listen thread.
  *
  * @return a value between {@link Thread#MIN_PRIORITY} and {@link Thread#MAX_PRIORITY}.
  * @since 1.2.2
  */
 public int getPriority() {
   ServerThread st = server;
   if (st != null) {
     return st.getPriority();
   } else {
     return Thread.NORM_PRIORITY;
   }
 }
コード例 #5
0
 /**
  * Listen for incoming and outgoing requests. If the <code>serverEnabled</code> member is <code>
  * false</code> the server for incoming requests is not started. This starts the internal server
  * thread that processes messages.
  *
  * @throws SocketException when the transport is already listening for incoming/outgoing messages.
  * @throws IOException
  */
 public synchronized void listen() throws java.io.IOException {
   if (server != null) {
     throw new SocketException("Port already listening");
   }
   server = new ServerThread();
   if (connectionTimeout > 0) {
     socketCleaner = new Timer(true); // run as daemon
   }
   server.setDaemon(true);
   server.start();
 }
コード例 #6
0
 /**
  * Sends a SNMP message to the supplied address.
  *
  * @param address an <code>TcpAddress</code>. A <code>ClassCastException</code> is thrown if
  *     <code>address</code> is not a <code>TcpAddress</code> instance.
  * @param message byte[] the message to sent.
  * @throws IOException
  */
 public void sendMessage(Address address, byte[] message) throws java.io.IOException {
   if (server == null) {
     listen();
   }
   server.sendMessage(address, message);
 }
コード例 #7
0
 /**
  * Sets the name of the listen thread for this UDP transport mapping. This method has no effect,
  * if called before {@link #listen()} has been called for this transport mapping.
  *
  * @param name the new thread name.
  * @since 1.6
  */
 public void setThreadName(String name) {
   ServerThread st = server;
   if (st != null) {
     st.setName(name);
   }
 }
コード例 #8
0
 /**
  * Changes the priority of the server thread for this TCP transport mapping. This method has no
  * effect, if called before {@link #listen()} has been called for this transport mapping.
  *
  * @param newPriority the new priority.
  * @see Thread#setPriority
  * @since 1.2.2
  */
 public void setPriority(int newPriority) {
   ServerThread st = server;
   if (st != null) {
     st.setPriority(newPriority);
   }
 }