當前位置: 首頁>>代碼示例>>Java>>正文


Java PortUnreachableException類代碼示例

本文整理匯總了Java中java.net.PortUnreachableException的典型用法代碼示例。如果您正苦於以下問題:Java PortUnreachableException類的具體用法?Java PortUnreachableException怎麽用?Java PortUnreachableException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PortUnreachableException類屬於java.net包,在下文中一共展示了PortUnreachableException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: connect

import java.net.PortUnreachableException; //導入依賴的package包/類
private void connect(String portName) throws Exception {
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    if (portIdentifier.isCurrentlyOwned())
        throw new PortInUseException();

    CommPort commPort = portIdentifier.open(this.getClass().getName(), COMPORT_PORT);

    if (commPort instanceof SerialPort) {
        SerialPort serialPort = (SerialPort) commPort;
        serialPort.setSerialPortParams(BAUD_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

        InputStream in = serialPort.getInputStream();
        OutputStream out = serialPort.getOutputStream();

        new Thread(new SerialReader(in)).start();
        new Thread(new SerialWriter(out)).start();

    } else {
        throw new PortUnreachableException("ERROR - Only serial ports are handled by this class");
    }

}
 
開發者ID:BenjiTrapp,項目名稱:GPSSimulator,代碼行數:23,代碼來源:TwoWaySerialComm.java

示例2: maybeThrowAfterRecvfrom

import java.net.PortUnreachableException; //導入依賴的package包/類
private static int maybeThrowAfterRecvfrom(boolean isRead, boolean isConnected, ErrnoException errnoException) throws SocketException, SocketTimeoutException {
    if (isRead) {
        if (errnoException.errno == EAGAIN) {
            return 0;
        } else {
            throw errnoException.rethrowAsSocketException();
        }
    } else {
        if (isConnected && errnoException.errno == ECONNREFUSED) {
            throw new PortUnreachableException("", errnoException);
        } else if (errnoException.errno == EAGAIN) {
            throw new SocketTimeoutException(errnoException);
        } else {
            throw errnoException.rethrowAsSocketException();
        }
    }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:18,代碼來源:IoBridge.java

示例3: throwAsIoOrRuntimeException

import java.net.PortUnreachableException; //導入依賴的package包/類
void throwAsIoOrRuntimeException(Throwable t) throws IOException {
    if (t instanceof PortUnreachableException && transport == Transport.UDP) {
        //This is an exception that may or may not happen, see the javadoc for DatagramSocket.send().
        //We don't want something this unreliable polluting the failure count.
        //With UDP syslogging set up against a non-existent syslog server:
        //On OS X this exception never happens.
        //On Linux this seems to happens every other send, so we end up with a loop
        //    odd send works; failure count = 0
        //    even send fails; failure count = 1
        //    odd send works; failure count reset to 0
        //
        //Also, we don't want the full stack trace for this which would get printed by StandardFailureCountHandler.StandardFailureCountHandler.failure(),
        //which also handles the failure count, so we swallow the exception and print a warning.

        ControllerLogger.MGMT_OP_LOGGER.udpSyslogServerUnavailable(getName(), t.getLocalizedMessage());
        return;
    }
    if (t instanceof IOException) {
        throw (IOException)t;
    }
    if (t instanceof RuntimeException) {
        throw (RuntimeException)t;
    }
    throw new RuntimeException(t);
}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:26,代碼來源:SyslogAuditLogHandler.java

示例4: run

import java.net.PortUnreachableException; //導入依賴的package包/類
public void run() {
   this.func_72609_b("Query running on " + this.field_72642_r + ":" + this.field_72636_h);
   this.field_72629_g = MinecraftServer.func_130071_aq();
   this.field_72631_o = new DatagramPacket(this.field_72630_n, this.field_72630_n.length);

   try {
      while(this.field_72619_a) {
         try {
            this.field_72633_m.receive(this.field_72631_o);
            this.func_72628_f();
            this.func_72621_a(this.field_72631_o);
         } catch (SocketTimeoutException var7) {
            this.func_72628_f();
         } catch (PortUnreachableException var8) {
            ;
         } catch (IOException var9) {
            this.func_72623_a(var9);
         }
      }
   } finally {
      this.func_72611_e();
   }

}
 
開發者ID:HATB0T,項目名稱:RuneCraftery,代碼行數:25,代碼來源:RConThreadQuery.java

示例5: run

import java.net.PortUnreachableException; //導入依賴的package包/類
public void run() {
    this.b("Query running on " + this.s + ":" + this.i);
    this.h = MinecraftServer.av();
    this.p = new DatagramPacket(this.o, this.o.length);

    try {
        while (this.a) {
            try {
                this.n.receive(this.p);
                this.f();
                this.a(this.p);
            } catch (SocketTimeoutException sockettimeoutexception) {
                this.f();
            } catch (PortUnreachableException portunreachableexception) {
                ;
            } catch (IOException ioexception) {
                this.a((Exception) ioexception);
            }
        }
    } finally {
        this.e();
    }

}
 
開發者ID:bergerkiller,項目名稱:SpigotSource,代碼行數:25,代碼來源:RemoteStatusListener.java

示例6: run

import java.net.PortUnreachableException; //導入依賴的package包/類
public void run()
{
    this.logInfo("Query running on " + this.serverHostname + ":" + this.queryPort);
    this.lastAuthCheckTime = MinecraftServer.getCurrentTimeMillis();
    this.incomingPacket = new DatagramPacket(this.buffer, this.buffer.length);

    try
    {
        while (this.running)
        {
            try
            {
                this.querySocket.receive(this.incomingPacket);
                this.cleanQueryClientsMap();
                this.parseIncomingPacket(this.incomingPacket);
            }
            catch (SocketTimeoutException var7)
            {
                this.cleanQueryClientsMap();
            }
            catch (PortUnreachableException var8)
            {
                ;
            }
            catch (IOException ioexception)
            {
                this.stopWithException(ioexception);
            }
        }
    }
    finally
    {
        this.closeAllSockets();
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:36,代碼來源:RConThreadQuery.java

示例7: isServerUnavailableException

import java.net.PortUnreachableException; //導入依賴的package包/類
public static boolean isServerUnavailableException(Throwable cause) {
    return isHttpException(cause, 503) ||
            (isException(cause, ConnectException.class)
            || isException(cause, NoRouteToHostException.class)
            || isException(cause, PortUnreachableException.class)
            || isException(cause, SocketTimeoutException.class));
}
 
開發者ID:jruesga,項目名稱:rview,代碼行數:8,代碼來源:ExceptionHelper.java

示例8: connectPortUnreachable

import java.net.PortUnreachableException; //導入依賴的package包/類
@Test
public void connectPortUnreachable() throws Exception {
    Mockito.doThrow(new PortUnreachableException()).when(mockSocket).connect(Mockito.any());

    final TcpCollector.ConnectDatum result;
    try (TcpCollector tcpCollector = new TcpCollector(dstAddress, GROUP)) {
        result = tcpCollector.tryConnect(mockSocket);
    }

    assertThat(result.getResult(), equalTo(TcpCollector.ConnectResult.PORT_UNREACHABLE));
    Mockito.verify(mockSocket, times(1)).connect(Mockito.eq(dstAddress));
    Mockito.verifyNoMoreInteractions(mockSocket);
}
 
開發者ID:groupon,項目名稱:monsoon,代碼行數:14,代碼來源:TcpCollectorTest.java

示例9: shouldHandleException

import java.net.PortUnreachableException; //導入依賴的package包/類
private boolean shouldHandleException(IOException ex) {
  // enumerate handled exceptions
  if (ex instanceof ConnectException ||
      ex instanceof NoRouteToHostException ||
      ex instanceof PortUnreachableException ||
      ex instanceof EOFException ||
      ex instanceof ConnectionClosedException) {
    return true;
  }
  if (ex instanceof RemoteException
      && ((RemoteException) ex).unwrapRemoteException() instanceof SafeModeException) {
    return true;
  }
  return false; // we rethrow all other exceptions (including remote exceptions
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:16,代碼來源:FailoverClientHandler.java

示例10: wrapException

import java.net.PortUnreachableException; //導入依賴的package包/類
/**
 * Take an IOException and the address we were trying to connect to
 * and return an IOException with the input exception as the cause.
 * The new exception provides the stack trace of the place where 
 * the exception is thrown and some extra diagnostics information.
 * If the exception is ConnectException or SocketTimeoutException, 
 * return a new one of the same type; Otherwise return an IOException.
 * 
 * @param addr target address
 * @param exception the relevant exception
 * @return an exception to throw
 */
private IOException wrapException(InetSocketAddress addr,
                                       IOException exception) {
  if (exception instanceof ConnectException) {
    //connection refused; include the host:port in the error
    return (ConnectException)new ConnectException(
         "Call to " + addr + " failed on connection exception: " + exception)
                  .initCause(exception);
  } else if (exception instanceof SocketTimeoutException) {
    return (SocketTimeoutException)new SocketTimeoutException(
         "Call to " + addr + " failed on socket timeout exception: "
                    + exception).initCause(exception);
  } else if (exception instanceof NoRouteToHostException) {
    return (NoRouteToHostException)new NoRouteToHostException(
         "Call to " + addr + " failed on NoRouteToHostException exception: "
                    + exception).initCause(exception);
  } else if (exception instanceof PortUnreachableException) {
    return (PortUnreachableException)new PortUnreachableException(
         "Call to " + addr + " failed on PortUnreachableException exception: "
                    + exception).initCause(exception);
  } else if (exception instanceof EOFException) {
      return (EOFException)new EOFException(
           "Call to " + addr + " failed on EOFException exception: "
                      + exception).initCause(exception);
  } else {
    return (IOException)new IOException(
         "Call to " + addr + " failed on local exception: " + exception)
                               .initCause(exception);

  }
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:43,代碼來源:Client.java

示例11: invoke

import java.net.PortUnreachableException; //導入依賴的package包/類
public Object invoke(Object proxy, Method method, Object[] args)
  throws Throwable {
  final boolean logDebug = !fastProtocol && LOG.isDebugEnabled();
  long startTime = 0;
  if (logDebug) {
    startTime = System.currentTimeMillis();
  }

  ObjectWritable value = null;
  try {
    String name = null;
    if (fastProtocol) {
      // try to obtain registered name for the method
      name = FastProtocolRegister.tryGetId(method);
    } 
    value = (ObjectWritable) client.call(new Invocation(method, name, args),
        getAddress(), protocol, ticket, rpcTimeout, fastProtocol);
  } catch (RemoteException re) {
    throw re;
  } catch (ConnectException ce) {
    needCheckDnsUpdate = true;
    throw ce;
  } catch (NoRouteToHostException nrhe) {
    needCheckDnsUpdate = true;
    throw nrhe;
  } catch (PortUnreachableException pue) {
    needCheckDnsUpdate = true;
    throw pue;
  } catch (UnknownHostException uhe) {
    needCheckDnsUpdate = true;
    throw uhe;
  } 
  if (logDebug) {
    long callTime = System.currentTimeMillis() - startTime;
    LOG.debug("Call: " + method.getName() + " " + callTime);
  }
  return value.get();
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:39,代碼來源:RPC.java

示例12: wakeUpIOS

import java.net.PortUnreachableException; //導入依賴的package包/類
/**
 * iOS devices are in a deep sleep mode, where they only listen to UDP traffic on port 5353 (Bonjour service
 * discovery). A packet on port 5353 will wake up the network stack to respond to ARP pings at least.
 *
 * @throws IOException
 */
public void wakeUpIOS(InetAddress address) throws IOException {
    try (DatagramSocket s = new DatagramSocket()) {
        byte[] buffer = new byte[0];
        s.send(new DatagramPacket(buffer, buffer.length, address, 5353));
    } catch (PortUnreachableException ignored) {
        // We ignore the port unreachable error
    }
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:15,代碼來源:NetworkUtils.java

示例13: send

import java.net.PortUnreachableException; //導入依賴的package包/類
/**
 * Send contents of a {@link ByteBuffer} to connected address.
 * This is used on the sender side for performance over send(ByteBuffer, SocketAddress).
 *
 * @param buffer to send
 * @return number of bytes sent
 */
public int send(final ByteBuffer buffer)
{
    int bytesSent = 0;

    if (null != sendDatagramChannel)
    {
        final int bytesToSend = buffer.remaining();

        if (null == multiDestination)
        {
            try
            {
                presend(buffer, connectAddress);
                bytesSent = sendDatagramChannel.write(buffer);
            }
            catch (final PortUnreachableException | ClosedChannelException | NotYetConnectedException ignore)
            {
            }
            catch (final IOException ex)
            {
                throw new RuntimeException("Failed to send packet of length: " + bytesToSend, ex);
            }
        }
        else
        {
            bytesSent = multiDestination.send(sendDatagramChannel, buffer, this, bytesToSend);
        }
    }

    return bytesSent;
}
 
開發者ID:real-logic,項目名稱:aeron,代碼行數:39,代碼來源:SendChannelEndpoint.java

示例14: send

import java.net.PortUnreachableException; //導入依賴的package包/類
int send(
    final DatagramChannel datagramChannel,
    final ByteBuffer buffer,
    final SendChannelEndpoint channelEndpoint,
    final int bytesToSend)
{
    final int position = buffer.position();
    int minBytesSent = bytesToSend;

    for (final InetSocketAddress destination : destinations)
    {
        int bytesSent = 0;
        try
        {
            channelEndpoint.presend(buffer, destination);

            buffer.position(position);
            bytesSent = datagramChannel.send(buffer, destination);
        }
        catch (final PortUnreachableException | ClosedChannelException ignore)
        {
        }
        catch (final IOException ex)
        {
            throw new RuntimeException("Failed to send: " + bytesToSend, ex);
        }

        minBytesSent = Math.min(minBytesSent, bytesSent);
    }

    return minBytesSent;
}
 
開發者ID:real-logic,項目名稱:aeron,代碼行數:33,代碼來源:MultiDestination.java

示例15: run

import java.net.PortUnreachableException; //導入依賴的package包/類
public void run()
{
    this.logInfo("Query running on " + this.serverHostname + ":" + this.queryPort);
    this.lastAuthCheckTime = MinecraftServer.getSystemTimeMillis();
    this.incomingPacket = new DatagramPacket(this.buffer, this.buffer.length);

    try
    {
        while (this.running)
        {
            try
            {
                this.querySocket.receive(this.incomingPacket);
                this.cleanQueryClientsMap();
                this.parseIncomingPacket(this.incomingPacket);
            }
            catch (SocketTimeoutException sockettimeoutexception)
            {
                this.cleanQueryClientsMap();
            }
            catch (PortUnreachableException portunreachableexception)
            {
                ;
            }
            catch (IOException ioexception)
            {
                this.stopWithException(ioexception);
            }
        }
    }
    finally
    {
        this.closeAllSockets();
    }
}
 
開發者ID:xtrafrancyz,項目名稱:Cauldron,代碼行數:36,代碼來源:RConThreadQuery.java


注:本文中的java.net.PortUnreachableException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。