List of usage examples for java.lang Thread start
public synchronized void start()
From source file:com.timtory.wmgallery.media.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;//ww w . j a v a2 s.co m options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; options.inPurgeable = true; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if (bitmap != null) { bitmap = Utils.resizeBitmap(context, bitmap, maxResolutionX); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { writeToCache(crc64, bitmap, maxResolutionX); } return bitmap; }
From source file:com.xlauncher.media.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;/*from w ww.ja v a 2 s. c o m*/ options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; options.inPurgeable = true; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if (bitmap != null) { bitmap = Utils.resizeBitmap(context, bitmap, maxResolutionX, false); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { writeToCache(crc64, bitmap, maxResolutionX); } return bitmap; }
From source file:com.keybox.manage.util.SSHUtil.java
/** * open new ssh session on host system/* www . ja v a2s . 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()); //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.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password"); 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()); } 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:com.iitb.cse.Utils.java
public static void sendApSettings(String settings) { String jsonString = Utils.getApSettingsFileJson(settings); for (DeviceInfo d : Constants.currentSession.getApConfFilteredDevices()) { int expId = Constants.currentSession.getCurrentExperimentId(); Thread sendData = new Thread(new SendData(expId, d, 3, jsonString)); sendData.start(); }//from www . ja v a2 s . co m }
From source file:io.fabric8.maven.core.util.ProcessUtil.java
private static Thread startErrorLoggingThread(final Process process, final Logger log, final String commandDesc, final boolean useStandardLoggingLevel) { Thread logThread = new Thread("[ERR] " + commandDesc) { @Override// w ww. j a v a2 s. co m public void run() { try { processOutput(process.getErrorStream(), createErrorHandler(log, useStandardLoggingLevel)); } catch (IOException e) { log.error("Failed to read error stream from %s : %s", commandDesc, e.getMessage()); } } }; logThread.setDaemon(true); logThread.start(); return logThread; }
From source file:io.fabric8.maven.core.util.ProcessUtil.java
private static Thread startOutputLoggingThread(final Process process, final Logger log, final String commandDesc, final boolean useStandardLoggingLevel) { Thread logThread = new Thread("[OUT] " + commandDesc) { @Override//from w ww . j a va2 s .c o m public void run() { try { processOutput(process.getInputStream(), createOutputHandler(log, useStandardLoggingLevel)); } catch (IOException e) { log.error("Failed to read output stream from %s : %s", commandDesc, e.getMessage()); } } }; logThread.setDaemon(true); logThread.start(); return logThread; }
From source file:it.cdpaf.helper.DrawableManager.java
public static ImageView fetchIvOnThread(String imagepath, int nthImage, final Context ctx) { final String urlString = Const.IMAGE_URL + imagepath; final Drawable resultDrawable; final ImageView imageView = new ImageView(ctx); String urlStringValid = ""; if (nthImage == 0) urlStringValid = urlString;/*from www . j a v a 2s. c o m*/ else { String url = urlString + "_" + nthImage; String[] result = urlString.split(".j"); String prima = result[0]; String seconda = result[1]; String jpg = ".j" + seconda; urlStringValid = prima + "_" + nthImage + jpg; } final String finalURl = urlStringValid; if (drawableMap.containsKey(urlStringValid)) { Log.d("ALL DRAWABLE", "INDIVIDUATO UN RIUSO : " + urlStringValid); resultDrawable = (drawableMap.get(urlStringValid)); imageView.setImageDrawable(resultDrawable); } else { final Handler handler = new Handler() { @Override public void handleMessage(Message message) { Drawable resDrawable = ((Drawable) message.obj); imageView.setImageDrawable(resDrawable); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(finalURl, ctx); Message messageb = handler.obtainMessage(1, drawable); handler.sendMessage(messageb); } }; Log.d("ALL DRAWABLE", "LANCIO UNA RICERCA : " + finalURl); thread.start(); } return imageView; }
From source file:org.wso2.carbon.inbound.endpoint.protocol.hl7.core.InboundHL7IOReactor.java
public static void start() throws IOException { if (reactor != null && reactor.getStatus().equals(IOReactorStatus.ACTIVE)) { return;//from w w w . java2s . c o m } IOReactorConfig config = getDefaultReactorConfig(); reactor = new DefaultListeningIOReactor(config); Thread reactorThread = new Thread(new Runnable() { @Override public void run() { try { isStarted = true; multiIOHandler = new MultiIOHandler(processorMap); log.info("MLLP Transport IO Reactor Started"); reactor.execute(multiIOHandler); } catch (IOException e) { isStarted = false; log.error("Error while starting the MLLP Transport IO Reactor.", e); } } }); reactorThread.start(); }
From source file:IOUtilities.java
/** * Loads data from the specified URLs asynchronously in a background thread. * Once all the data is loaded, it is passed to the specified * <code>DataReceiver</code>. <code>id</code> is a convenience allowing the * receiver to identify the data - it is merely passed back to the receiver. *///from w ww . j ava2 s .c om public static void loadAsynchronously(URL[] urls, Object id, DataReceiver receiver, boolean allowCache) { Thread asyncReader = new Thread(new UrlDataReader((URL[]) urls.clone(), id, receiver, allowCache), "AsyncThread-" + (++UrlDataReader.threadCount)); asyncReader.setDaemon(true); asyncReader.start(); }
From source file:edu.umass.cs.contextservice.installer.CSInstaller.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 a v a 2 s .c o m*/ * @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 deleteDatabase, String scriptFile, boolean withGNS) { ArrayList<Thread> threads = new ArrayList<>(); Enumeration<String> keyIter = hostTable.keys(); while (keyIter.hasMoreElements()) { String nodeId = keyIter.nextElement(); String hostname = hostTable.get(nodeId); threads.add(new UpdateThread(hostname, nodeId, action, deleteDatabase, scriptFile, withGNS)); } 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); } // if (action != InstallerAction.STOP) { // updateNodeConfigAndSendOutServerInit(); // } System.out.println("Finished " + name + " " + action.name() + " at " + new Date().toString()); }