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


Java ConnectException類代碼示例

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


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

示例1: getExternalServiceException

import java.rmi.ConnectException; //導入依賴的package包/類
public static ExternalServiceException getExternalServiceException(Exception e) {
    if (e instanceof ExternalServiceException) {
        return (ExternalServiceException) e;
    } else if (e instanceof RemoteException) {
        if (isLocalProblem((RemoteException) e)) {
            return new ExternalServiceException("Communication with the server could not be started.", e);
        }
        return new ExternalServiceException("An error occurred on the external server side.", e);
    } else if (e instanceof RuntimeException) {
        return new ExternalServiceException("An unexpected error occurred in the server. [" + e.getMessage() + "]", e);
    } else if (e instanceof HttpException) {
        return new ExternalServiceException("Unexpected error occurred in HTTP communication with external server. [" + e.getMessage() + "]", e);
    } else if (e instanceof ConnectException) {
        return new ExternalServiceException("Could not connect to external server. [" + e.getMessage() + "]", e);
    } else if (e instanceof IOException) {
        return new ExternalServiceException("An unexpected error occurred in the I / O with the external server. [" + e.getMessage() + "]", e);
    }
    return new ExternalServiceException("An unexpected error occurred. Response=[" + e.getMessage() + "]", e);
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:20,代碼來源:ExceptionUtils.java

示例2: agentmain

import java.rmi.ConnectException; //導入依賴的package包/類
public static void agentmain(String args, Instrumentation instrumentation) throws RemoteException {
    String name = null;
    for (String arg : args.split(",")) {
        if (arg.startsWith("name=")) {
            name = arg.replace("name=", "");
        }
    }
    if (name == null) {
        throw new IllegalArgumentException("The name to use for the rmi server was not provided as an argument to the java agent.");
    }
    Registry registry = LocateRegistry.getRegistry();
    if (registry != null) {
        DefaultServerImpl rmi = new DefaultServerImpl(ClassLoader.getSystemClassLoader());
        try {
            //Attempt to bind to the registry stub that was returned.
            registry.rebind(name, rmi);
        } catch (ConnectException ce) {
            //Couldn't bind to it (perhaps it doesn't exist), creating a new one.
            registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
            registry.rebind(name, rmi);
        }
    }
}
 
開發者ID:ccarpenter04,項目名稱:Cross-JVM-Reflection,代碼行數:24,代碼來源:JavaAgent.java

示例3: newCall

import java.rmi.ConnectException; //導入依賴的package包/類
/**
 * @deprecated
 */
public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum,
                          long hash) throws RemoteException
{
  UnicastConnection conn;

  try
    {
      conn = manager.getConnection();
    }
  catch (IOException e1)
    {
      throw new ConnectException("connection failed to host: "
                                 + manager.serverName, e1);
    }

  // obj: useless?

  return (new UnicastRemoteCall(conn, objid, opnum, hash));
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:23,代碼來源:UnicastRef.java

示例4: getRealRun

import java.rmi.ConnectException; //導入依賴的package包/類
@Override
protected RemoteSingleRun getRealRun(UsernamePrincipal creator,
		Workflow workflow, UUID id) throws Exception {
	@Nonnull
	byte[] wf = serializeWorkflow(workflow);
	for (int i = 0; i < 3; i++) {
		initFactory();
		try {
			return getRealRun(creator, wf, id);
		} catch (ConnectException | ConnectIOException e) {
			// factory was lost; try to recreate
		}
		killFactory();
	}
	throw new NoCreateException("total failure to connect to factory "
			+ factoryProcessName + "despite attempting restart");
}
 
開發者ID:apache,項目名稱:incubator-taverna-server,代碼行數:18,代碼來源:ForkRunFactory.java

示例5: getRealRun

import java.rmi.ConnectException; //導入依賴的package包/類
@Override
protected RemoteSingleRun getRealRun(UsernamePrincipal creator,
		Workflow workflow, UUID id) throws Exception {
	byte[] wf = serializeWorkflow(workflow);
	String username = mapper == null ? null : mapper
			.getUsernameForPrincipal(creator);
	if (username == null)
		throw new Exception("cannot determine who to run workflow as; "
				+ "local identity mapper returned null");
	for (int i = 0; i < 3; i++) {
		if (!factory.containsKey(username))
			initFactory(username);
		try {
			return getRealRun(creator, username, wf, id);
		} catch (ConnectException | ConnectIOException e) {
			// factory was lost; try to recreate
		}
		factory.remove(username);
	}
	throw new NoCreateException("total failure to connect to factory "
			+ factoryProcessName + "despite attempting restart");
}
 
開發者ID:apache,項目名稱:incubator-taverna-server,代碼行數:23,代碼來源:IdAwareForkRunFactory.java

示例6: run

import java.rmi.ConnectException; //導入依賴的package包/類
@Override
public void run() {

	final String name = root.getAbsolutePath();
	InetAddress current = null;
	try {
		current = InetAddress.getLocalHost();
	} catch (final UnknownHostException e1) {
		e1.printStackTrace();
		return;
	}
	try {
		try {
			// first try to call existing service
			invoke(current, name);

		} catch (final ConnectException e) {
			startInvoker(name);
			invoke(current, name);
		}
	} catch (final Throwable t) {
		t.printStackTrace();
	}
}
 
開發者ID:lucee,項目名稱:Lucee,代碼行數:25,代碼來源:CLIFactory.java

示例7: run

import java.rmi.ConnectException; //導入依賴的package包/類
public void run()
{
	try{
		//System.out.println("heartbeat");
		String[] putarr = new String[putList.size()];
		putList.toArray(putarr);
		pk.heartbeat(putarr, sessionid);
	}catch(Exception e){
		//e.printStackTrace();
		LogUtil.info("[PutHbTask]", "[heartbeat:]", e.getMessage());
		//this.cancel();
		//HbDaemo.tm.cancel();
		if(e instanceof ConnectException){
			this.pk = pl.getNextLeader();
		}
	}
}
 
開發者ID:muzi666boy,項目名稱:fourinone,代碼行數:18,代碼來源:HbDaemo.java

示例8: getClientConnection

import java.rmi.ConnectException; //導入依賴的package包/類
static final AbstractClientConnection getClientConnection(Endpoint ep)
        throws IOException, UnknownHostException, ConnectException,
        ConnectIOException {
    Socket sock = null;
    AbstractClientConnection ret;
    
    RMIClientSocketFactory csf = (ep.getCsf() != null) ? ep.getCsf()
            : RMISocketFactory.getSocketFactory();
    if (csf == null) {
        csf = RMISocketFactory.getDefaultSocketFactory();
    }
    sock = csf.createSocket(ep.getEndpointID().getHost(), ep.getPort());
    if (SO_TIME_OUT != 0) {
        sock.setSoTimeout(SO_TIME_OUT);
    }
    sock.setTcpNoDelay(true);
    if (sock instanceof HttpSocketClientSide) {
        ret = new SingleOpClientConnection(sock, ep);
    } else {
        ret = new StreamClientConnection(sock, ep);
    }
    return ret;
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:24,代碼來源:ClientConnectionFactory.java

示例9: isLocalProblem

import java.rmi.ConnectException; //導入依賴的package包/類
public static boolean isLocalProblem(RemoteException e) {
    if (e instanceof ConnectIOException) {
        return true;
    } else if (e instanceof ConnectException) {
        return true;
    } else if (e instanceof UnknownHostException) {
        return true;
    }
    return false;
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:11,代碼來源:ExceptionUtils.java

示例10: doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh

import java.rmi.ConnectException; //導入依賴的package包/類
private void doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(
		boolean lookupHomeOnStartup, boolean cacheHome) throws Exception {

	final RemoteInterface ejb = mock(RemoteInterface.class);
	given(ejb.targetMethod()).willThrow(new ConnectException(""));

	int lookupCount = 2;
	if (!cacheHome) {
		lookupCount++;
		if (lookupHomeOnStartup) {
			lookupCount++;
		}
	}

	final String jndiName= "foobar";
	Context mockContext = mockContext(jndiName, ejb);

	SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
	si.setRefreshHomeOnConnectFailure(true);
	si.setLookupHomeOnStartup(lookupHomeOnStartup);
	si.setCacheHome(cacheHome);

	RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
	try {
		target.targetMethod();
		fail("Should have thrown RemoteException");
	}
	catch (ConnectException ex) {
		// expected
	}

	verify(mockContext, times(lookupCount)).close();
	verify(ejb, times(2)).remove();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:35,代碼來源:SimpleRemoteSlsbInvokerInterceptorTests.java

示例11: declaresException

import java.rmi.ConnectException; //導入依賴的package包/類
@Test
public void declaresException() throws Exception {
	Method remoteExMethod = A.class.getDeclaredMethod("foo", Integer.class);
	assertTrue(ReflectionUtils.declaresException(remoteExMethod, RemoteException.class));
	assertTrue(ReflectionUtils.declaresException(remoteExMethod, ConnectException.class));
	assertFalse(ReflectionUtils.declaresException(remoteExMethod, NoSuchMethodException.class));
	assertFalse(ReflectionUtils.declaresException(remoteExMethod, Exception.class));

	Method illegalExMethod = B.class.getDeclaredMethod("bar", String.class);
	assertTrue(ReflectionUtils.declaresException(illegalExMethod, IllegalArgumentException.class));
	assertTrue(ReflectionUtils.declaresException(illegalExMethod, NumberFormatException.class));
	assertFalse(ReflectionUtils.declaresException(illegalExMethod, IllegalStateException.class));
	assertFalse(ReflectionUtils.declaresException(illegalExMethod, Exception.class));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:ReflectionUtilsTests.java

示例12: emitChunksWithError

import java.rmi.ConnectException; //導入依賴的package包/類
private Observable<HttpResponseChunk> emitChunksWithError(final int statusCode, final int restarts,
        final int events) {
    final AtomicInteger restartCounter = new AtomicInteger(0);
    return Observable.defer(() -> {
            final int restart = restartCounter.incrementAndGet();
            final Observable<HttpResponseChunk> chunks = emitRange(statusCode, restarts, events, restart);
            final Throwable t = restart % 2 == 0 ? new SocketTimeoutException("Test Socket timeout")
                                                 : new ConnectException("Test Connection failed");
            return Observable.concat(chunks, Observable.error(t));
        });
}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:12,代碼來源:HttpReactiveReceiverTest.java

示例13: isConnectOrCloseException

import java.rmi.ConnectException; //導入依賴的package包/類
public static boolean isConnectOrCloseException(Throwable e) {
    if (e instanceof ConnectException && 
        e.getCause() != null && 
        e.getCause() instanceof IOException) {
        
        if (e.getCause() instanceof ClosedChannelException || e.getCause() instanceof java.net.ConnectException) {
            return true;
        }

        if (e.getCause().getMessage() != null && e.getCause().getMessage().contains("aborted")) {
            return true;
        }

        if (e.getCause().getMessage() != null && e.getCause().getMessage().contains("Connection reset by peer")) {
            return true;
        }
    }
    if(e instanceof LRMINoSuchObjectException) {
        return true;
    }
    if (e instanceof IOException) {
        if (e.getMessage() != null && e.getMessage().startsWith("Connection reset by peer")) {
            return true;
        }
    }
    return false;
}
 
開發者ID:Gigaspaces,項目名稱:xap-openspaces,代碼行數:28,代碼來源:NetworkExceptionHelper.java

示例14: createRMIClient

import java.rmi.ConnectException; //導入依賴的package包/類
/**
 * 創建建立 RMI 客戶端 並連接
 *
 * @throws RemoteException
 *             遠程異常
 * @throws NotBoundException
 *             未綁定異常
 */
private boolean createRMIClient() {

	// ready address and port
	String address = getServerConfig().getMasterAddress();
	int port = getServerConfig().getMasterPort();

	// try to connect
	try {
		logger.info("正在創建 RMI 客戶端....");

		Registry masterRegistry = LocateRegistry.getRegistry(address, port,
				new SslRMIClientSocketFactory());

		_masterServer = (MasterRMIServerInterface) masterRegistry
				.lookup("MasterServer");
		_masterServer.ping();
		boolean success = _masterServer.registerServer(getServerConfig()
				.getServerKey(), _masterClientObj);
		if (!success) {
			logger.error("注冊服務失敗!...");
		} else {
			logger.info("已經成功注冊上管理服務...");
			return true;
		}
	} catch (ConnectException connectException) {
		logger.error(" 嘗試連接到     MasterServer  連接失敗  :: ({}:{})[{}]", address,
				port, connectException.getMessage());
	} catch (RemoteException | NotBoundException ex) {
		logger.error("注冊服務失敗:", ex);
	}
	return false;
}
 
開發者ID:316181444,項目名稱:GameServerFramework,代碼行數:41,代碼來源:AbstractRMIServerClient.java

示例15: getRemoteFactoryHandle

import java.rmi.ConnectException; //導入依賴的package包/類
private RemoteRunFactory getRemoteFactoryHandle(String name)
		throws RemoteException, NotBoundException {
	log.info("about to look up resource called " + name);
	try {
		// Validate registry connection first
		getTheRegistry().list();
	} catch (ConnectException | ConnectIOException e) {
		log.warn("connection problems with registry", e);
	}
	RemoteRunFactory rrf = (RemoteRunFactory) getTheRegistry().lookup(name);
	log.info("successfully connected to factory subprocess "
			+ factoryProcessName);
	return rrf;
}
 
開發者ID:apache,項目名稱:incubator-taverna-server,代碼行數:15,代碼來源:ForkRunFactory.java


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