List of usage examples for java.lang Thread start
public synchronized void start()
From source file:com.iitb.cse.Utils.java
public static void sendHeartBeatDuration(String duration) { String jsonString = Utils.getHeartBeatDuration(duration); for (DeviceInfo d : Constants.currentSession.getConfigFilteredDevices()) { Thread sendData = new Thread( new SendData(Constants.currentSession.getCurrentExperimentId(), d, 5, jsonString)); sendData.start(); }//ww w .ja v a2s.c o m }
From source file:com.iitb.cse.Utils.java
public static void sendServerConfiguration(String serverIP, String serverPORT, String connectionPORT) { String jsonString = Utils.getServerConfiguration(serverIP, serverPORT, connectionPORT); for (DeviceInfo d : Constants.currentSession.getConfigFilteredDevices()) { Thread sendData = new Thread( new SendData(Constants.currentSession.getCurrentExperimentId(), d, 6, jsonString)); sendData.start(); }/*from w w w .j a va 2 s . c om*/ }
From source file:com.iitb.cse.Utils.java
public static void sendStopExperiment(int expid) { DBManager.updateStopExperiment(expid); String jsonString = Utils.getStopSignalJson(); for (DeviceInfo d : Constants.currentSession.getFilteredClients()) { Thread sendData = new Thread( new SendData(Constants.currentSession.getCurrentExperimentId(), d, 1, jsonString)); sendData.start(); }//w w w . java 2 s.com }
From source file:it.cdpaf.helper.DrawableManager.java
public static void fetchDrawableOnThread(final Category cat, final ImageView imageView, final Context ctx) { final String urlString = Const.IMAGE_URL + cat.getNomeImmagine(); if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); //product.setImmagine(drawableMap.get(urlString)); }//ww w.j a v a 2 s .c o m final Handler handler = new Handler() { @Override public void handleMessage(Message message) { Drawable dr = (Drawable) message.obj; imageView.setImageDrawable(dr); cat.setImmagine(dr); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable d = ctx.getResources().getDrawable(R.drawable.ic_launcher); Message messagea = handler.obtainMessage(1, d); handler.sendMessage(messagea); Drawable drawable = fetchDrawable(urlString, ctx); Message messageb = handler.obtainMessage(1, drawable); handler.sendMessage(messageb); } }; thread.start(); }
From source file:it.cdpaf.helper.DrawableManager.java
public static void fetchDrawableOnThread(final Macrocategory mac, final ImageView imageView, final Context ctx) { final String urlString = Const.IMAGE_URL + mac.getNomeImmagine(); if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); //product.setImmagine(drawableMap.get(urlString)); }// w w w . jav a 2 s .c o m final Handler handler = new Handler() { @Override public void handleMessage(Message message) { Drawable dr = (Drawable) message.obj; imageView.setImageDrawable(dr); mac.setImmagine(dr); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable d = ctx.getResources().getDrawable(R.drawable.ic_launcher); Message messagea = handler.obtainMessage(1, d); handler.sendMessage(messagea); Drawable drawable = fetchDrawable(urlString, ctx); Message messageb = handler.obtainMessage(1, drawable); handler.sendMessage(messageb); } }; thread.start(); }
From source file:edu.umass.cs.gnsserver.installer.GNSInstaller.java
/** * Copies the latest version of the JAR files to the all the hosts in the installation given by name and restarts all the servers. * Does this using a separate Thread for each host. * * * @param name//from www.j av a2 s . c om * @param action * @param removeLogs * @param deleteDatabase * @param lnsHostsFile * @param nsHostsFile * @param scriptFile * @param runAsRoot * @param noopTest */ public static void updateRunSet(String name, InstallerAction action, boolean removeLogs, boolean deleteDatabase, String lnsHostsFile, String nsHostsFile, String scriptFile, boolean runAsRoot, boolean noopTest) { ArrayList<Thread> threads = new ArrayList<>(); for (HostInfo info : hostTable.values()) { threads.add(new UpdateThread(info.getHostname(), info.getNsId(), noopTest ? false : info.isCreateLNS(), action, removeLogs, deleteDatabase, lnsHostsFile, nsHostsFile, scriptFile, runAsRoot, noopTest)); } for (Thread thread : threads) { thread.start(); } // and wait for them to complete try { for (Thread thread : threads) { thread.join(); } } catch (InterruptedException e) { System.out.println("Problem joining threads: " + e); } System.out .println("Finished " + name + " " + action.name() + " at " + Format.formatDateTimeOnly(new Date())); }
From source file:com.tascape.qa.th.Utils.java
public static void deleteFileAfterMinutes(final File file, final int minutes) { file.deleteOnExit();/*from w ww. j av a 2s. co m*/ Thread t = new Thread() { @Override public void run() { try { Thread.sleep(minutes * 60000); FileUtils.deleteQuietly(file); } catch (InterruptedException ex) { LOG.trace(ex.getMessage()); } } }; t.setDaemon(true); t.start(); }
From source file:com.tethrnet.manage.util.SSHUtil.java
/** * open new ssh session on host system/*from w w w .j av a 2 s . com*/ * * @param passphrase key passphrase for instance * @param password password for instance * @param userId user id * @param sessionId session id * @param hostSystem host system * @param userSessionMap user session map * @return status of systems */ public static HostSystem openSSHTermOnSystem(String passphrase, String password, Long userId, Long sessionId, HostSystem hostSystem, Map<Long, UserSchSessions> userSessionMap) { JSch jsch = new JSch(); int instanceId = getNextInstanceId(sessionId, userSessionMap); hostSystem.setStatusCd(HostSystem.SUCCESS_STATUS); hostSystem.setInstanceId(instanceId); SchSession schSession = null; try { // ApplicationKey appKey = PrivateKeyDB.getApplicationKey(); // //check to see if passphrase has been provided // if (passphrase == null || passphrase.trim().equals("")) { // passphrase = appKey.getPassphrase(); // //check for null inorder to use key without passphrase // if (passphrase == null) { // passphrase = ""; // } // } // //add private key // jsch.addIdentity(appKey.getId().toString(), appKey.getPrivateKey().trim().getBytes(), appKey.getPublicKey().getBytes(), passphrase.getBytes()); jsch.addIdentity(hostSystem.getAuthorizedKeys()); //create session Session session = jsch.getSession(hostSystem.getUser(), hostSystem.getHost(), hostSystem.getPort()); //set password if it exists if (password != null && !password.trim().equals("")) { session.setPassword(password); } session.setConfig("StrictHostKeyChecking", "no"); session.setServerAliveInterval(SERVER_ALIVE_INTERVAL); session.connect(SESSION_TIMEOUT); Channel channel = session.openChannel("shell"); if ("true".equals(AppConfig.getProperty("agentForwarding"))) { ((ChannelShell) channel).setAgentForwarding(true); } ((ChannelShell) channel).setPtyType("xterm"); InputStream outFromChannel = channel.getInputStream(); //new session output SessionOutput sessionOutput = new SessionOutput(sessionId, hostSystem); Runnable run = new SecureShellTask(sessionOutput, outFromChannel); Thread thread = new Thread(run); thread.start(); OutputStream inputToChannel = channel.getOutputStream(); PrintStream commander = new PrintStream(inputToChannel, true); channel.connect(); schSession = new SchSession(); schSession.setUserId(userId); schSession.setSession(session); schSession.setChannel(channel); schSession.setCommander(commander); schSession.setInputToChannel(inputToChannel); schSession.setOutFromChannel(outFromChannel); schSession.setHostSystem(hostSystem); //refresh keys for session // addPubKey(hostSystem, session, appKey.getPublicKey()); addPubKey(hostSystem, session, ""); } catch (Exception e) { log.info(e.toString(), e); hostSystem.setErrorMsg(e.getMessage()); if (e.getMessage().toLowerCase().contains("userauth fail")) { hostSystem.setStatusCd(HostSystem.PUBLIC_KEY_FAIL_STATUS); } else if (e.getMessage().toLowerCase().contains("auth fail") || e.getMessage().toLowerCase().contains("auth cancel")) { hostSystem.setStatusCd(HostSystem.AUTH_FAIL_STATUS); } else if (e.getMessage().toLowerCase().contains("unknownhostexception")) { hostSystem.setErrorMsg("DNS Lookup Failed"); hostSystem.setStatusCd(HostSystem.HOST_FAIL_STATUS); } else { hostSystem.setStatusCd(HostSystem.GENERIC_FAIL_STATUS); } } //add session to map if (hostSystem.getStatusCd().equals(HostSystem.SUCCESS_STATUS)) { //get the server maps for user UserSchSessions userSchSessions = userSessionMap.get(sessionId); //if no user session create a new one if (userSchSessions == null) { userSchSessions = new UserSchSessions(); } Map<Integer, SchSession> schSessionMap = userSchSessions.getSchSessionMap(); //add server information schSessionMap.put(instanceId, schSession); userSchSessions.setSchSessionMap(schSessionMap); //add back to map userSessionMap.put(sessionId, userSchSessions); } SystemStatusDB.updateSystemStatus(hostSystem, userId); SystemDB.updateSystem(hostSystem); return hostSystem; }
From source file:collabedit.Telnet.java
public static void init() { String remoteip = "23.102.136.121"; int remoteport = 4500; tc = new TelnetClient(); TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false); EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false); SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true); try {/*from ww w . j a v a 2 s . c o m*/ tc.addOptionHandler(ttopt); tc.addOptionHandler(echoopt); tc.addOptionHandler(gaopt); } catch (InvalidTelnetOptionException e) { System.err.println("Error registering option handlers: " + e.getMessage()); } try { tc.connect(remoteip, remoteport); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Thread reader = new Thread(new Telnet()); tc.registerNotifHandler(new Telnet()); System.out.println("TelnetClientExample"); System.out.println("Type AYT to send an AYT telnet command"); System.out.println("Type OPT to print a report of status of options (0-24)"); System.out.println("Type REGISTER to register a new SimpleOptionHandler"); System.out.println("Type UNREGISTER to unregister an OptionHandler"); System.out.println("Type SPY to register the spy (connect to port 3333 to spy)"); System.out.println("Type UNSPY to stop spying the connection"); reader.start(); OutputStream outstr = tc.getOutputStream(); System.out.println("Telnet started"); }
From source file:com.iitb.cse.Utils.java
public static void requestLogFiles(final int clientsPerRound, final int roundGap, String[] clientList) { Constants.currentSession.setFetchingLogFiles(true); // final int Runnable run = new Runnable() { @Override// www . jav a2 s.c om public void run() { try { int requested = 0; Enumeration<String> macList = Constants.currentSession.getGetLogFilefFilteredDevices().keys(); while (macList.hasMoreElements()) { String macAddr = macList.nextElement(); String json = Utils.getLogFilesJson(1); DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr); System.out.println("\nMac Addr : " + macAddr); System.out.println("\nJson : " + json); Thread sendData = new Thread(new SendData(1, d, 4, json)); sendData.start(); requested++; if (requested == clientsPerRound) { requested = 0; try { Thread.sleep(roundGap * 1000); // seconds } catch (InterruptedException ex) { System.out.println(ex.toString()); } } } } catch (Exception ex) { System.out.println("\nException ex" + ex.toString()); } } }; Thread t = new Thread(run); t.start(); // Constants.currentSession.setFetchingLogFiles(false); // int totalClients = clientList.length; // if (clientsPerRound >= Constants.currentSession.getGetLogFilefFilteredDevices().size()) { // // Enumeration<String> macList = Constants.currentSession.getGetLogFilefFilteredDevices().keys(); // while (macList.hasMoreElements()) { // String macAddr = macList.nextElement(); // String json = Utils.getLogFilesJson(1); // DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr); // System.out.println("\nMac Addr : " + macAddr); // System.out.println("\nJson : " + json); // Thread sendData = new Thread(new SendData(1, d, 4, json)); // sendData.start(); // } // for (String client : clientList) { // // String value[] = client.split("_"); // int expID = Integer.parseInt(value[0]); // String macAddr = value[1]; // String json = Utils.getLogFilesJson(expID); // DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr); // System.out.println("\nMac Addr : " + macAddr); // System.out.println("\nJson : " + json); // Thread sendData = new Thread(new SendData(expID, d, 4, json)); // sendData.start(); // } // } else { // // int requested = 0; // // Enumeration<String> macList = Constants.currentSession.getGetLogFilefFilteredDevices().keys(); // while (macList.hasMoreElements()) { // String macAddr = macList.nextElement(); // String json = Utils.getLogFilesJson(1); // DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr); // System.out.println("\nMac Addr : " + macAddr); // System.out.println("\nJson : " + json); // Thread sendData = new Thread(new SendData(1, d, 4, json)); // sendData.start(); // requested++; // // if (requested == clientsPerRound) { // requested = 0; // try { // Thread.sleep(roundGap * 1000); // seconds // } catch (InterruptedException ex) { // System.out.println(ex.toString()); // } // } // } // while (totalClients > 0) { // // if (totalClients > clientsPerRound) { // // for (int i = 0; i < clientsPerRound; i++) { // String value[] = clientList[index].split("_"); // int expID = Integer.parseInt(value[0]); // String macAddr = value[1]; // String json = Utils.getLogFilesJson(expID); // DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr); // System.out.println("\nMac Addr : " + macAddr); // System.out.println("\nJson : " + json); // Thread sendData = new Thread(new SendData(expID, d, 4, json)); // sendData.start(); // index++; // } // totalClients = totalClients - clientsPerRound; // } else { // // for (int i = 0; i < totalClients; i++) { // // String value[] = clientList[index].split("_"); // int expID = Integer.parseInt(value[0]); // String macAddr = value[1]; // String json = Utils.getLogFilesJson(expID); // DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr); // System.out.println("\nMac Addr : " + macAddr); // System.out.println("\nJson : " + json); // Thread sendData = new Thread(new SendData(expID, d, 4, json)); // sendData.start(); // index++; // } // totalClients = 0; // } // // try { // Thread.sleep(roundGap * 1000); // seconds // } catch (InterruptedException ex) { // System.out.println(ex.toString()); // } // } }