List of usage examples for java.net InetSocketAddress InetSocketAddress
private InetSocketAddress(int port, String hostname)
From source file:eu.stratosphere.addons.visualization.swt.SWTVisualization.java
public static void main(String[] args) { // First, look for -configDir parameter String configDir = null;//ww w . jav a 2 s. co m for (int i = 0; i < (args.length - 1); i++) { if (CONFIG_DIR_PARAMETER.equals(args[i])) { configDir = args[i + 1]; break; } } if (configDir == null) { LOG.error("Please specify Nephele configuration directory with " + CONFIG_DIR_PARAMETER); System.exit(1); return; } // Try to load global configuration GlobalConfiguration.loadConfiguration(configDir); final String address = GlobalConfiguration.getString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, null); if (address == null) { LOG.error("Cannot find address to job manager's RPC service in configuration"); System.exit(1); return; } final int port = GlobalConfiguration.getInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, -1); if (port < 0) { LOG.error("Cannot find port to job manager's RPC service in configuration"); System.exit(1); return; } final InetSocketAddress inetaddr = new InetSocketAddress(address, port); ExtendedManagementProtocol jobManager; int queryInterval = -1; try { jobManager = (ExtendedManagementProtocol) RPC.getProxy(ExtendedManagementProtocol.class, inetaddr, NetUtils.getSocketFactory()); // Get the query interval queryInterval = jobManager.getRecommendedPollingInterval().getValue(); } catch (IOException e) { e.printStackTrace(); System.exit(1); return; } final SWTVisualizationGUI swtVisualizationGUI = new SWTVisualizationGUI(jobManager, queryInterval); final Shell shell = swtVisualizationGUI.getShell(); final Display display = swtVisualizationGUI.getDisplay(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:com.ok2c.lightmtp.examples.LocalMailClientTransportExample.java
public static void main(final String[] args) throws Exception { String text1 = "From: root\r\n" + "To: testuser1\r\n" + "Subject: test message 1\r\n" + "\r\n" + "This is a short test message 1\r\n"; String text2 = "From: root\r\n" + "To: testuser1, testuser2\r\n" + "Subject: test message 2\r\n" + "\r\n" + "This is a short test message 2\r\n"; String text3 = "From: root\r\n" + "To: testuser1, testuser2, testuser3\r\n" + "Subject: test message 3\r\n" + "\r\n" + "This is a short test message 3\r\n"; DeliveryRequest request1 = new BasicDeliveryRequest("root", Arrays.asList("testuser1"), new ByteArraySource(text1.getBytes("US-ASCII"))); DeliveryRequest request2 = new BasicDeliveryRequest("root", Arrays.asList("testuser1", "testuser2"), new ByteArraySource(text2.getBytes("US-ASCII"))); DeliveryRequest request3 = new BasicDeliveryRequest("root", Arrays.asList("testuser1", "testuser2", "testuser3"), new ByteArraySource(text3.getBytes("US-ASCII"))); Queue<DeliveryRequest> queue = new ConcurrentLinkedQueue<DeliveryRequest>(); queue.add(request1);//w w w . j av a 2 s.c om queue.add(request2); queue.add(request3); CountDownLatch messageCount = new CountDownLatch(queue.size()); IOReactorConfig config = IOReactorConfig.custom().setIoThreadCount(1).build(); MailClientTransport mua = new LocalMailClientTransport(config); mua.start(new MyDeliveryRequestHandler(messageCount)); SessionEndpoint endpoint = new SessionEndpoint(new InetSocketAddress("localhost", 2525)); SessionRequest sessionRequest = mua.connect(endpoint, queue, null); sessionRequest.waitFor(); IOSession iosession = sessionRequest.getSession(); if (iosession != null) { messageCount.await(); } else { IOException ex = sessionRequest.getException(); if (ex != null) { System.out.println("Connection failed: " + ex.getMessage()); } } System.out.println("Shutting down I/O reactor"); try { mua.shutdown(); } catch (IOException ex) { mua.forceShutdown(); } System.out.println("Done"); }
From source file:com.interacciones.mxcashmarketdata.driver.client.DriverClient.java
public static void main(String[] args) throws Throwable { init(args);//from w w w. j ava2 s . c o m NioSocketConnector connector = new NioSocketConnector(); // Configure the service. connector.setConnectTimeoutMillis(CONNECT_TIMEOUT); if (USE_CUSTOM_CODEC) { connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new SumUpProtocolCodecFactory(false))); } else { connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); } int[] values = new int[] {}; connector.getFilterChain().addLast("logger", new LoggingFilter()); connector.setHandler(new ClientSessionHandler(values)); long time = System.currentTimeMillis(); IoSession session; for (;;) { try { System.out.println(host + " " + port + " " + fileTest); ConnectFuture future = connector.connect(new InetSocketAddress(host, port)); future.awaitUninterruptibly(); session = future.getSession(); File file = new File(fileTest); FileInputStream is = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); int data = br.read(); int count = 0; IoBuffer ib = IoBuffer.allocate(274); ib.setAutoExpand(true); boolean flagcount = false; while (data != -1) { data = br.read(); ib.put((byte) data); if (flagcount) { count++; } if (data == 13) { count = 1; flagcount = true; LOGGER.debug(ib.toString()); } if (count == 4) { ib.flip(); session.write(ib); ib = IoBuffer.allocate(274); ib.setAutoExpand(true); flagcount = false; count = 0; //Thread.sleep(500); } } break; } catch (RuntimeIoException e) { LOGGER.error("Failed to connect."); e.printStackTrace(); Thread.sleep(5000); } } time = System.currentTimeMillis() - time; LOGGER.info("Time " + time); // wait until the summation is done session.getCloseFuture().awaitUninterruptibly(); connector.dispose(); }
From source file:de.htwg_konstanz.in.uce.hp.parallel.integration_test.TargetMock.java
public static void main(String[] args) throws IOException { CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); Option o = new Option("m", "mediatorIP", true, "mediator ip"); o.setRequired(true);// w ww. ja v a 2 s .c o m options.addOption(o); o = new Option("p", "mediatorPort", true, "mediator port"); o.setRequired(true); options.addOption(o); o = new Option("t", "targetId", true, "target ID"); o.setRequired(true); options.addOption(o); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("TargetMock", options); return; } String mediatorIP = cmd.getOptionValue("mediatorIP"); String mediatorPort = cmd.getOptionValue("mediatorPort"); String targetId = cmd.getOptionValue("targetId"); InetSocketAddress mediatorSocketAddress; try { int port = Integer.parseInt(mediatorPort); mediatorSocketAddress = new InetSocketAddress(mediatorIP, port); } catch (NumberFormatException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } catch (IllegalArgumentException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } new TargetMock(mediatorSocketAddress, targetId).start(); }
From source file:edu.umass.cs.reconfiguration.reconfigurationpackets.RequestActiveReplicas.java
public static void main(String[] args) { String[] addrs = { "128.119.240.21" }; int[] ports = { 3245 }; assert (addrs.length == ports.length); InetSocketAddress[] isaddrs = new InetSocketAddress[addrs.length]; try {//from w w w. ja v a 2 s.c o m for (int i = 0; i < addrs.length; i++) { isaddrs[i] = new InetSocketAddress(InetAddress.getByName(addrs[i]), ports[i]); } String name = "name"; InetSocketAddress sender = new InetSocketAddress(InetAddress.getLoopbackAddress(), 1234); RequestActiveReplicas req1 = new RequestActiveReplicas(sender, name, 0); System.out.println(req1); JSONObject json1; json1 = req1.toJSONObject(); RequestActiveReplicas req2 = new RequestActiveReplicas(json1, null); System.out.println(req2); } catch (UnknownHostException | JSONException e) { e.printStackTrace(); } }
From source file:com.github.sdnwiselab.sdnwise.mote.standalone.Loader.java
/** * @param args the command line arguments *//*from w ww . java 2 s . co m*/ public static void main(final String[] args) { Options options = new Options(); options.addOption(Option.builder("n").argName("net").hasArg().required().desc("Network ID of the node") .numberOfArgs(1).build()); options.addOption(Option.builder("a").argName("address").hasArg().required() .desc("Address of the node <0-65535>").numberOfArgs(1).build()); options.addOption(Option.builder("p").argName("port").hasArg().required().desc("Listening UDP port") .numberOfArgs(1).build()); options.addOption(Option.builder("t").argName("filename").hasArg().required() .desc("Use given file for neighbors discovery").numberOfArgs(1).build()); options.addOption(Option.builder("c").argName("ip:port").hasArg() .desc("IP address and TCP port of the controller. (SINK ONLY)").numberOfArgs(1).build()); options.addOption(Option.builder("sp").argName("port").hasArg() .desc("Port number of the switch. (SINK ONLY)").numberOfArgs(1).build()); options.addOption(Option.builder("sm").argName("mac").hasArg() .desc("MAC address of the switch. Example: <00:00:00:00:00:00>." + " (SINK ONLY)").numberOfArgs(1) .build()); options.addOption(Option.builder("sd").argName("dpid").hasArg().desc("DPID of the switch (SINK ONLY)") .numberOfArgs(1).build()); options.addOption(Option.builder("l").argName("level").hasArg() .desc("Use given log level. Values: SEVERE, WARNING, INFO, " + "CONFIG, FINE, FINER, FINEST.") .numberOfArgs(1).optionalArg(true).build()); // create the parser CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(options, args); Thread th; byte cmdNet = (byte) Integer.parseInt(line.getOptionValue("n")); NodeAddress cmdAddress = new NodeAddress(Integer.parseInt(line.getOptionValue("a"))); int cmdPort = Integer.parseInt(line.getOptionValue("p")); String cmdTopo = line.getOptionValue("t"); String cmdLevel; if (!line.hasOption("l")) { cmdLevel = "SEVERE"; } else { cmdLevel = line.getOptionValue("l"); } if (line.hasOption("c")) { if (!line.hasOption("sd")) { throw new ParseException("-sd option missing"); } if (!line.hasOption("sp")) { throw new ParseException("-sp option missing"); } if (!line.hasOption("sm")) { throw new ParseException("-sm option missing"); } String cmdSDpid = line.getOptionValue("sd"); String cmdSMac = line.getOptionValue("sm"); long cmdSPort = Long.parseLong(line.getOptionValue("sp")); String[] ipport = line.getOptionValue("c").split(":"); th = new Thread(new Sink(cmdNet, cmdAddress, cmdPort, new InetSocketAddress(ipport[0], Integer.parseInt(ipport[1])), cmdTopo, cmdLevel, cmdSDpid, cmdSMac, cmdSPort)); } else { th = new Thread(new Mote(cmdNet, cmdAddress, cmdPort, cmdTopo, cmdLevel)); } th.start(); th.join(); } catch (InterruptedException | ParseException ex) { System.out.println("Parsing failed. Reason: " + ex.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sdn-wise-data -n id -a address -p port" + " -t filename [-l level] [-sd dpid -sm mac -sp port]", options); } }
From source file:de.htwg_konstanz.in.uce.hp.parallel.integration_test.SourceMock.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); Option o = new Option("m", "mediatorIP", true, "mediator ip"); o.setRequired(true);/*from ww w. ja v a 2 s . c om*/ options.addOption(o); o = new Option("p", "mediatorPort", true, "mediator port"); o.setRequired(true); options.addOption(o); o = new Option("t", "targetId", true, "target ID"); o.setRequired(true); options.addOption(o); o = new Option("d", "description", true, "scenario description"); o.setRequired(true); options.addOption(o); o = new Option("sin", "numberOfsimultaneousConnections", true, "number of simultaneous " + "connections"); o.setRequired(false); options.addOption(o); o = new Option("si", "simultaneousConnections", false, "simultaneous connections test"); o.setRequired(false); options.addOption(o); o = new Option("su", "successiveConnections", false, "successive connections test"); o.setRequired(false); options.addOption(o); o = new Option("r", "realisticConnections", false, "realistic connections test"); o.setRequired(false); options.addOption(o); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } String mediatorIP = cmd.getOptionValue("mediatorIP"); String mediatorPort = cmd.getOptionValue("mediatorPort"); String description = cmd.getOptionValue("description"); String targetId = cmd.getOptionValue("targetId"); InetSocketAddress mediatorSocketAddress; try { int port = Integer.parseInt(mediatorPort); mediatorSocketAddress = new InetSocketAddress(mediatorIP, port); } catch (NumberFormatException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } catch (IllegalArgumentException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } if (cmd.hasOption("numberOfsimultaneousConnections")) { int simConnections = Integer.parseInt(cmd.getOptionValue("numberOfsimultaneousConnections")); new SourceMock(description, targetId, mediatorSocketAddress, simConnections).runTests( cmd.hasOption("simultaneousConnections"), cmd.hasOption("successiveConnections"), cmd.hasOption("realisticConnections")); } else { new SourceMock(description, targetId, mediatorSocketAddress).runTests( cmd.hasOption("simultaneousConnections"), cmd.hasOption("successiveConnections"), cmd.hasOption("realisticConnections")); } }
From source file:org.eclipse.ecf.provider.filetransfer.httpcore.NHttpClient.java
public static void main(String[] args) throws Exception { HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1"); final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, params); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new RequestContent()); httpproc.addInterceptor(new RequestTargetHost()); httpproc.addInterceptor(new RequestConnControl()); httpproc.addInterceptor(new RequestUserAgent()); httpproc.addInterceptor(new RequestExpectContinue()); // We are going to use this object to synchronize between the // I/O event and main threads //CountDownLatch requestCount = new CountDownLatch(3); CountDownLatch requestCount = new CountDownLatch(1); BufferingHttpClientHandler handler = new MyBufferingHttpClientHandler(httpproc, new MyHttpRequestExecutionHandler(requestCount), new DefaultConnectionReuseStrategy(), params); handler.setEventListener(new EventLogger()); final IOEventDispatch ioEventDispatch = new DefaultClientIOEventDispatch(handler, params); Thread t = new Thread(new Runnable() { public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); }/*from w ww . j ava 2 s .com*/ System.out.println("Shutdown"); } }); t.start(); SessionRequest[] reqs = new SessionRequest[1]; reqs[0] = ioReactor.connect(new InetSocketAddress("ftp.osuosl.org", 80), null, new HttpHost("ftp.osuosl.org"), new MySessionRequestCallback(requestCount)); // Block until all connections signal // completion of the request execution requestCount.await(); System.out.println("Shutting down I/O reactor"); ioReactor.shutdown(); System.out.println("Done"); }
From source file:NHttpClient.java
public static void main(String[] args) throws Exception { HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1"); final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, params); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new RequestContent()); httpproc.addInterceptor(new RequestTargetHost()); httpproc.addInterceptor(new RequestConnControl()); httpproc.addInterceptor(new RequestUserAgent()); httpproc.addInterceptor(new RequestExpectContinue()); // We are going to use this object to synchronize between the // I/O event and main threads CountDownLatch requestCount = new CountDownLatch(3); BufferingHttpClientHandler handler = new BufferingHttpClientHandler(httpproc, new MyHttpRequestExecutionHandler(requestCount), new DefaultConnectionReuseStrategy(), params); handler.setEventListener(new EventLogger()); final IOEventDispatch ioEventDispatch = new DefaultClientIOEventDispatch(handler, params); Thread t = new Thread(new Runnable() { public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); }/* w w w. java2 s.c om*/ System.out.println("Shutdown"); } }); t.start(); SessionRequest[] reqs = new SessionRequest[3]; reqs[0] = ioReactor.connect(new InetSocketAddress("www.yahoo.com", 80), null, new HttpHost("www.yahoo.com"), new MySessionRequestCallback(requestCount)); reqs[1] = ioReactor.connect(new InetSocketAddress("www.google.com", 80), null, new HttpHost("www.google.ch"), new MySessionRequestCallback(requestCount)); reqs[2] = ioReactor.connect(new InetSocketAddress("www.apache.org", 80), null, new HttpHost("www.apache.org"), new MySessionRequestCallback(requestCount)); // Block until all connections signal // completion of the request execution requestCount.await(); System.out.println("Shutting down I/O reactor"); ioReactor.shutdown(); System.out.println("Done"); }
From source file:com.github.brandtg.switchboard.MysqlReplicator.java
/** Main. */ public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("u", "user", true, "MySQL user"); options.addOption("p", "password", true, "MySQL password"); options.addOption("h", "host", true, "MySQL host"); options.addOption("P", "port", true, "MySQL port"); options.addOption("s", "sinkPort", true, "Local sink port"); options.addOption("l", "lastIndex", true, "Last transaction ID"); options.addOption("h", "help", false, "Prints help message"); CommandLine commandLine = new GnuParser().parse(options, args); if (commandLine.getArgs().length < 2 || commandLine.hasOption("help")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("usage: [opts] switchboardHost:port db1 [db2 ...]", options); System.exit(1);// ww w . jav a 2 s .co m } // Switchboard host String[] hostPort = commandLine.getArgs()[0].split(":"); InetSocketAddress source = new InetSocketAddress(hostPort[0], Integer.valueOf(hostPort[1])); InetSocketAddress sink = new InetSocketAddress( Integer.valueOf(commandLine.getOptionValue("sinkPort", "9090"))); // Databases to replicate String[] databases = Arrays.copyOfRange(commandLine.getArgs(), 1, commandLine.getArgs().length); // JDBC params for local copy String user = commandLine.getOptionValue("user", "root"); String password = commandLine.getOptionValue("password", ""); String jdbcString = String.format("jdbc:mysql://%s:%d", commandLine.getOptionValue("host", "localhost"), Integer.valueOf(commandLine.getOptionValue("port", "3306"))); Long lastIndex = Long.valueOf(commandLine.getOptionValue("lastIndex", "-1")); // Create replicators final List<MysqlReplicator> replicators = new ArrayList<>(); for (String database : databases) { MysqlReplicator replicator = new MysqlReplicator(database, source, sink, jdbcString, user, password, lastIndex); replicators.add(replicator); } // Shutdown hook Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { for (MysqlReplicator replicator : replicators) { try { replicator.shutdown(); } catch (Exception e) { LOG.error("Could not shut down {}", replicator, e); } } } }); for (MysqlReplicator replicator : replicators) { replicator.start(); LOG.info("Started {}", replicator); } }