List of usage examples for java.net InetSocketAddress getAddress
public final InetAddress getAddress()
From source file:com.all.dht.DhtManager.java
private void processOversizedValueRequest(AllMessage<String> message) { String senderId = message.getProperty(MESSAGE_SENDER); if (senderId != null && !dht.getLocalNodeID().toHexString().equals(senderId)) { log.info("Processing OVERSIZED_DHT_VALUE_REQUEST_TYPE for key : " + message.getBody()); Contact sender = dht.getRouteTable().get(KUID.createWithHexString(senderId)); InetSocketAddress senderAddress = (InetSocketAddress) sender.getContactAddress(); byte[] oversizedValue = dhtFileUtils.readFromFileSystem(message.getBody()); if (oversizedValue != null) { AllMessage<String> response = new AllMessage<String>(OVERSIZED_DHT_VALUE_RESPONSE_TYPE, new String(oversizedValue)); response.putProperty(MESSAGE_SENDER, dht.getLocalNodeID().toHexString()); response.putProperty(DHT_PRIMARY_KEY, message.getBody()); networkingService.send(dht.getLocalNodeID().toHexString(), response, senderAddress.getAddress().getHostAddress(), senderAddress.getPort() + 1); }/*from ww w . j a va2 s . c o m*/ } }
From source file:com.thejoshwa.ultrasonic.androidapp.service.ssl.SSLSocketFactory.java
/** * @since 4.1//from w ww.ja v a2 s. co m */ public Socket connectSocket(final Socket sock, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (remoteAddress == null) { throw new IllegalArgumentException("Remote address may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } SSLSocket sslsock = (SSLSocket) (sock != null ? sock : createSocket()); if (localAddress != null) { // sslsock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params)); sslsock.bind(localAddress); } int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); try { sslsock.connect(remoteAddress, connTimeout); } catch (SocketTimeoutException ex) { throw new ConnectTimeoutException( "Connect to " + remoteAddress.getHostName() + "/" + remoteAddress.getAddress() + " timed out"); } sslsock.setSoTimeout(soTimeout); if (this.hostnameVerifier != null) { try { this.hostnameVerifier.verify(remoteAddress.getHostName(), sslsock); // verifyHostName() didn't blowup - good! } catch (IOException iox) { // close the socket before re-throwing the exception try { sslsock.close(); } catch (Exception x) { /*ignore*/ } throw iox; } } return sslsock; }
From source file:uk.ac.gla.terrier.probos.controller.ControllerServer.java
protected int yarnJob(final JobInformation ji, final String requestorUserName) throws IOException { assert ji.scriptLocation != null; assert ji.folderLocation != null; final PBSJob job = ji.jobSpec; PrivilegedExceptionAction<Integer> submitAction = new PrivilegedExceptionAction<Integer>() { public Integer run() throws Exception { File luaFile = writeJobKittenSpec(job, ji.scriptLocation, ji.jobId, false); Configuration kConf = new Configuration(yConf); kConf.set(LocalDataHelper.APP_BASE_DIR, ji.folderLocation.toUri().toString()); YarnClientParameters params = new LuaYarnClientParameters(luaFile.toString(), Constants.PRODUCT_NAME, kConf, extraLuaValues, extraLocalResources); ji.jobSpec.setQueue(params.getQueue()); Credentials creds = new Credentials(); //create delegation tokens //interactive rpc InetSocketAddress addr = NetUtils.getConnectAddress(interactiveRpcserver); Text host = new Text(addr.getAddress().getHostAddress() + ":" + addr.getPort()); ProbosDelegationTokenIdentifier tokenId = secretManager.createIdentifier(); Token<ProbosDelegationTokenIdentifier> delgationToken = new Token<ProbosDelegationTokenIdentifier>( tokenId, secretManager); delgationToken.setService(host); creds.addToken(host, delgationToken); LOG.info("Interactive: Generated token for " + creds.toString() + " : " + delgationToken); //client rpc tokenId = secretManager.createIdentifier(); delgationToken = new Token<ProbosDelegationTokenIdentifier>(tokenId, secretManager); addr = NetUtils.getConnectAddress(clientRpcserver); host = new Text(addr.getAddress().getHostAddress() + ":" + addr.getPort()); delgationToken.setService(host); creds.addToken(host, delgationToken); LOG.info("Client: Generated token for " + creds.toString() + " : " + delgationToken); //master rpc tokenId = secretManager.createIdentifier(); delgationToken = new Token<ProbosDelegationTokenIdentifier>(tokenId, secretManager); addr = NetUtils.getConnectAddress(masterRpcserver); host = new Text(addr.getAddress().getHostAddress() + ":" + addr.getPort()); delgationToken.setService(host); creds.addToken(host, delgationToken); LOG.info("Master: Generated token for " + creds.toString() + " : " + delgationToken); YarnClientService service = new YarnClientServiceImpl(params, creds); service.startAndWait();/* w w w. jav a2 s .c o m*/ if (!service.isRunning()) { LOG.error("YarnClientService failed to startup, exiting..."); jobArray.remove(ji.jobId); return ji.jobId; } ji.kitten = service; ji.modify(); return ji.jobId; } }; //setuid to the requestor's user id UserGroupInformation proxyUser = UserGroupInformation.createProxyUser(requestorUserName, UserGroupInformation.getLoginUser()); Integer rtr = null; try { if (UserGroupInformation.isSecurityEnabled()) rtr = proxyUser.doAs(submitAction); else rtr = submitAction.run(); ji.proxyUser = proxyUser; ji.modify(); runningJobs.inc(); return rtr.intValue(); } catch (Exception e) { LOG.error("job did not submit!", e); return -1; } }
From source file:edu.umass.cs.reconfiguration.ActiveReplica.java
@SuppressWarnings({ "unchecked", "unused" }) @Deprecated/*from ww w .ja v a 2 s . com*/ private AddressMessenger<JSONObject> initClientMessenger() { AbstractPacketDemultiplexer<JSONObject> pd = null; Messenger<InetSocketAddress, JSONObject> cMsgr = null; Set<IntegerPacketType> appTypes = null; if ((appTypes = this.appCoordinator.getAppRequestTypes()) == null || appTypes.isEmpty()) return null; try { int myPort = (this.nodeConfig.getNodePort(getMyID())); if (getClientFacingPort(myPort) != myPort) { log.log(Level.INFO, "{0} creating client messenger at {1}:{2}", new Object[] { this, this.nodeConfig.getBindAddress(getMyID()), getClientFacingPort(myPort) }); if (this.messenger.getClientMessenger() == null || this.messenger.getClientMessenger() != this.messenger) { MessageNIOTransport<InetSocketAddress, JSONObject> niot = null; InetSocketAddress isa = new InetSocketAddress(this.nodeConfig.getBindAddress(getMyID()), getClientFacingPort(myPort)); cMsgr = new JSONMessenger<InetSocketAddress>( niot = new MessageNIOTransport<InetSocketAddress, JSONObject>(isa.getAddress(), isa.getPort(), /* Client facing demultiplexer is single * threaded to keep clients from * overwhelming the system with request * load. */ (pd = new ReconfigurationPacketDemultiplexer()), ReconfigurationConfig.getClientSSLMode())); if (!niot.getListeningSocketAddress().equals(isa)) throw new IOException("Unable to listen on specified client facing socket address " + isa); } else if (this.messenger.getClientMessenger() instanceof Messenger) ((Messenger<NodeIDType, ?>) this.messenger.getClientMessenger()) .addPacketDemultiplexer(pd = new ReconfigurationPacketDemultiplexer(0)); pd.register(this.appCoordinator.getAppRequestTypes(), this); } } catch (IOException e) { e.printStackTrace(); log.severe(this + ":" + e.getMessage()); System.exit(1); } return cMsgr != null ? cMsgr : (AddressMessenger<JSONObject>) this.messenger; }
From source file:eu.stratosphere.nephele.taskmanager.TaskManager.java
/** * Find out the TaskManager's own IP address. *///from w w w . ja v a 2 s. c o m private InetAddress getTaskManagerAddress(InetSocketAddress jobManagerAddress) throws IOException { AddressDetectionState strategy = AddressDetectionState.ADDRESS; while (true) { Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { NetworkInterface n = e.nextElement(); Enumeration<InetAddress> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = ee.nextElement(); switch (strategy) { case ADDRESS: if (hasCommonPrefix(jobManagerAddress.getAddress().getAddress(), i.getAddress())) { if (tryToConnect(i, jobManagerAddress, strategy.getTimeout())) { LOG.info("Determined " + i + " as the TaskTracker's own IP address"); return i; } } break; case FAST_CONNECT: case SLOW_CONNECT: boolean correct = tryToConnect(i, jobManagerAddress, strategy.getTimeout()); if (correct) { LOG.info("Determined " + i + " as the TaskTracker's own IP address"); return i; } break; default: throw new RuntimeException("Unkown address detection strategy: " + strategy); } } } // state control switch (strategy) { case ADDRESS: strategy = AddressDetectionState.FAST_CONNECT; break; case FAST_CONNECT: strategy = AddressDetectionState.SLOW_CONNECT; break; case SLOW_CONNECT: throw new RuntimeException("The TaskManager failed to detect its own IP address"); } if (LOG.isDebugEnabled()) { LOG.debug("Defaulting to detection strategy " + strategy); } } }
From source file:org.apache.hadoop.hdfs.qjournal.server.JournalNodeJournalSyncer.java
void recoverSegment(InetSocketAddress jn, EditLogFile relf, SyncTask task) throws IOException { try {/* w ww .j av a2 s .c o m*/ // we are looking for finalized segments that we do not have // we only care about segments within the range final long remoteStartTxid = relf.getFirstTxId(); final long remoteEndTxid = relf.getLastTxId(); if (remoteStartTxid >= task.recoveryStartTxid && remoteStartTxid <= task.recoveryEndTxid && remoteEndTxid <= task.recoveryEndTxid && !relf.isInProgress() && !task.containsValidSegment(relf)) { String name = "[" + remoteStartTxid + " : " + remoteEndTxid + "]"; LOG.info(logMsg + "attempting recovery for segment " + name + " for journal id: " + task.journal.getJournalId()); // path to download String path = GetJournalEditServlet.buildPath(task.journal.getJournalId(), remoteStartTxid, task.journal.getJournalStorage(), 0); // url to download URL url = new URL("http", jn.getAddress().getHostAddress(), jn.getPort(), path.toString()); // download temporary file File syncedTmpFile = task.journal.getJournalStorage().getSyncLogTemporaryFile(relf.getFirstTxId(), relf.getLastTxId(), now()); // .tmp file will not interfere with storage syncedTmpFile = task.journal.syncLog(now(), relf.getFirstTxId(), url, name, syncedTmpFile); // final destination of the file File syncedDestFile = task.journal.getJournalStorage().getSyncLogDestFile(relf.getFirstTxId(), relf.getLastTxId()); if (syncedDestFile == null) { throwIOException(logMsg + " Error when recovering log " + relf); } // synchronized on journal so no files can be changed synchronized (task.journal) { // move away our local copy of the segment EditLogFile localCorruptedFile = null; try { localCorruptedFile = task.getInprogressSegment(remoteStartTxid); if (localCorruptedFile != null) { localCorruptedFile.moveAsideCorruptFile(); } } catch (Exception e) { LOG.warn(logMsg + "exception when marking segment: " + localCorruptedFile + " as corrupt.", e); } // move tmp file to finalized log segment FileUtil.replaceFile(syncedTmpFile, syncedDestFile); } // add the segment to the list so we do not recover it again task.addValidSegment(relf); LOG.info(logMsg + "successfully recovered segment " + name + " for journal id: " + task.journal.getJournalId()); InjectionHandler.processEvent(InjectionEvent.QJM_JOURNALNODE_RECOVERY_COMPLETED); } } catch (Exception e) { LOG.warn(logMsg + "exception when recovering segment: " + relf.toColonSeparatedString() + " when trying with journal node: " + jn, e); } }
From source file:edu.umass.cs.reconfiguration.ActiveReplica.java
@SuppressWarnings("unchecked") private AddressMessenger<?> initClientMessenger(boolean ssl) { AbstractPacketDemultiplexer<JSONObject> pd = null; Messenger<InetSocketAddress, JSONObject> cMsgr = null; Set<IntegerPacketType> appTypes = null; if ((appTypes = this.appCoordinator.getAppRequestTypes()) == null || appTypes.isEmpty()) // return null ;//from ww w . jav a2 s .c om try { int myPort = (this.nodeConfig.getNodePort(getMyID())); if ((ssl ? getClientFacingSSLPort(myPort) : getClientFacingClearPort(myPort)) != myPort) { log.log(Level.INFO, "{0} creating {1} client messenger at {2}:{3}", new Object[] { this, ssl ? "SSL" : "", this.nodeConfig.getBindAddress(getMyID()), "" + (ssl ? getClientFacingSSLPort(myPort) : getClientFacingClearPort(myPort)) }); AddressMessenger<?> existing = (ssl ? this.messenger.getSSLClientMessenger() : this.messenger.getClientMessenger()); if (existing == null || existing == this.messenger) { MessageNIOTransport<InetSocketAddress, JSONObject> niot = null; InetSocketAddress isa = new InetSocketAddress(this.nodeConfig.getBindAddress(getMyID()), ssl ? getClientFacingSSLPort(myPort) : getClientFacingClearPort(myPort)); cMsgr = new JSONMessenger<InetSocketAddress>( (niot = new MessageNIOTransport<InetSocketAddress, JSONObject>(isa.getAddress(), isa.getPort(), /* Client facing demultiplexer is single * threaded to keep clients from * overwhelming the system with request * load. */ (pd = new ReconfigurationPacketDemultiplexer()), ssl ? ReconfigurationConfig.getClientSSLMode() : SSL_MODES.CLEAR)) .setName(this.appCoordinator.app.toString() + ":" + (ssl ? "SSL" : "") + "ClientMessenger")); if (!niot.getListeningSocketAddress().equals(isa)) throw new IOException("Unable to listen on specified client facing socket address " + isa + "; created messenger listening instead on " + niot.getListeningSocketAddress()); } else if (!ssl) { log.log(Level.INFO, "{0} adding self as demultiplexer to existing {1} client messenger", new Object[] { this, ssl ? "SSL" : "" }); if (this.messenger.getClientMessenger() instanceof Messenger) ((Messenger<NodeIDType, ?>) existing) .addPacketDemultiplexer(pd = new ReconfigurationPacketDemultiplexer()); } else { log.log(Level.INFO, "{0} adding self as demultiplexer to existing {1} client messenger", new Object[] { this, ssl ? "SSL" : "" }); if (this.messenger.getSSLClientMessenger() instanceof Messenger) ((Messenger<NodeIDType, ?>) existing) .addPacketDemultiplexer(pd = new ReconfigurationPacketDemultiplexer()); } if (appTypes != null && !appTypes.isEmpty()) pd.register(appTypes //this.appCoordinator.getRequestTypes() , this); pd.register(PacketType.ECHO_REQUEST, this); pd.register(PacketType.REPLICABLE_CLIENT_REQUEST, this); } } catch (IOException e) { e.printStackTrace(); log.severe(this + ":" + e.getMessage()); System.exit(1); } if (cMsgr != null) if (ssl && this.messenger.getSSLClientMessenger() == null) this.messenger.setSSLClientMessenger(cMsgr); else if (!ssl && this.messenger.getClientMessenger() == null) this.messenger.setClientMessenger(cMsgr); return cMsgr != null ? cMsgr : (AddressMessenger<?>) this.messenger; }
From source file:github.popeen.dsub.service.ssl.SSLSocketFactory.java
/** * @since 4.1//from w ww. jav a2s . com */ public Socket connectSocket(final Socket sock, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (remoteAddress == null) { throw new IllegalArgumentException("Remote address may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } SSLSocket sslsock = (SSLSocket) (sock != null ? sock : createSocket()); if (localAddress != null) { // sslsock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params)); sslsock.bind(localAddress); } setHostName(sslsock, remoteAddress.getHostName()); int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); try { sslsock.connect(remoteAddress, connTimeout); } catch (SocketTimeoutException ex) { throw new ConnectTimeoutException( "Connect to " + remoteAddress.getHostName() + "/" + remoteAddress.getAddress() + " timed out"); } sslsock.setSoTimeout(soTimeout); if (this.hostnameVerifier != null) { try { this.hostnameVerifier.verify(remoteAddress.getHostName(), sslsock); // verifyHostName() didn't blowup - good! } catch (IOException iox) { // close the socket before re-throwing the exception try { sslsock.close(); } catch (Exception x) { /*ignore*/ } throw iox; } } return sslsock; }
From source file:edu.umass.cs.reconfiguration.Reconfigurator.java
private static Set<InetSocketAddress> modifyPortsForSSL(Set<InetSocketAddress> replicas, Boolean ssl) { if (ssl == null) return replicas; else if ((ssl && ReconfigurationConfig.getClientPortSSLOffset() == 0) || (!ssl && ReconfigurationConfig.getClientPortOffset() == 0)) return replicas; Set<InetSocketAddress> modified = new HashSet<InetSocketAddress>(); for (InetSocketAddress sockAddr : replicas) modified.add(new InetSocketAddress(sockAddr.getAddress(), ssl ? ReconfigurationConfig.getClientFacingSSLPort(sockAddr.getPort()) : ReconfigurationConfig.getClientFacingClearPort(sockAddr.getPort()))); return modified; }
From source file:org.apache.hadoop.hdfs.server.datanode.BPOfferService.java
BPOfferService(List<InetSocketAddress> nnAddrs, DataNode dn) { Preconditions.checkArgument(!nnAddrs.isEmpty(), "Must pass at least one NN."); this.dn = dn; for (InetSocketAddress addr : nnAddrs) { this.bpServices.add(new BPServiceActor(addr, this)); nnList.add(new ActiveNodePBImpl(0, "", addr.getAddress().getHostAddress(), addr.getPort(), "", addr.getAddress().getHostAddress(), addr.getPort())); }//from w w w .j a va2s . c om dnConf = dn.getDnConf(); prevBlockReportId = DFSUtil.getRandom().nextLong(); }