List of usage examples for java.lang Object wait
public final void wait() throws InterruptedException
From source file:Wake.java
public void stopOne() { Object myLock = new Object(); synchronized (myLock) { stopped.addElement(myLock);/*from w w w . j av a 2s.co m*/ try { myLock.wait(); } catch (InterruptedException e) { } } }
From source file:com.lucidtechnics.blackboard.Launcher.java
public void launch() { final Blackboard blackboard = new Blackboard(); java.io.File currentDirectory = new java.io.File("."); TargetSpace targetSpace = new TargetSpaceImpl(); targetSpace.setBlackboard(blackboard); logger.info("the current directory is: " + currentDirectory.getName()); java.io.File[] generatorArray = currentDirectory.listFiles(); for (int i = 0; i < generatorArray.length; i++) { com.lucidtechnics.blackboard.Plan plan = null; if (generatorArray[i].isDirectory() == false && generatorArray[i].getName().endsWith("blackboard.configuration.js") == false) { if (generatorArray[i].isDirectory() == false && generatorArray[i].getName().endsWith(".js") == true) { logger.info("Executing generator: " + generatorArray[i].getName()); plan = new JavaScriptPlan(); } else if (generatorArray[i].isDirectory() == false && generatorArray[i].getName().contains("blackboard.configuration") == false) { String[] tokenArray = generatorArray[i].getName().split("\\."); String extension = tokenArray[tokenArray.length - 1]; if (Jsr223Plan.hasScriptingEngine(extension) == true) { logger.info("Executing generator: " + generatorArray[i].getName()); plan = new Jsr223Plan(extension); }/*from w ww .ja va 2 s. c om*/ } if (plan != null) { plan.setName(generatorArray[i].getName()); plan.setPath(generatorArray[i].getAbsolutePath()); plan.execute(new com.lucidtechnics.blackboard.WorkspaceContext(targetSpace, plan)); } } } logger.info("Driver execution is completed. Plans may still be processing."); Object object = new Object(); synchronized (object) { try { object.wait(); } catch (InterruptedException e) { } } }
From source file:com.boothj5.minions.MinionsRunner.java
void run() throws MinionsException { try {/*from w w w. java2s .com*/ LOG.debug("Starting MinionsRunner"); ConnectionConfiguration connectionConfiguration; if (StringUtils.isNotBlank(config.getServer())) { connectionConfiguration = new ConnectionConfiguration(config.getServer(), config.getPort(), config.getService()); } else { connectionConfiguration = new ConnectionConfiguration(config.getService(), config.getPort()); } XMPPConnection conn = new XMPPConnection(connectionConfiguration); conn.connect(); conn.login(config.getUser(), config.getPassword(), config.getResource()); LOG.debug(format("Logged in: %s@%s", config.getUser(), config.getService())); MultiUserChat muc = new MultiUserChat(conn, config.getRoom()); if (StringUtils.isBlank(config.getRoomPassword())) { muc.join(config.getRoomNick()); } else { muc.join(config.getRoomNick(), config.getRoomPassword()); } LOG.debug(format("Joined: %s as %s", config.getRoom(), config.getRoomNick())); MinionStore minions = new MinionStore(config.getPluginsDir(), config.getRefreshSeconds(), muc); MinionsListener listener = new MinionsListener(minions, config.getPrefix(), muc, config.getRoomNick()); muc.addMessageListener(listener); Object lock = new Object(); synchronized (lock) { while (true) { lock.wait(); } } } catch (Throwable t) { throw new MinionsException(t); } }
From source file:ThreadPool.java
public void addRequestAndWait(Runnable target) throws InterruptedException { Object lock = new Object(); synchronized (lock) { add(target, lock);/*from w ww . jav a 2s .c om*/ lock.wait(); } }
From source file:org.objectweb.proactive.core.runtime.StartPARuntime.java
public void waitUntilInterupted() { Object o = new Object(); synchronized (o) { try {/* ww w. j ava2s . co m*/ o.wait(); } catch (InterruptedException e) { logger.info(e); } } }
From source file:io.teak.sdk.Amazon.java
public JSONObject querySkuDetails(String sku) { try {//from ww w. jav a2 s.co m Class<?> purchasingServiceClass = Class.forName("com.amazon.device.iap.PurchasingService"); Method m = purchasingServiceClass.getMethod("getProductData", Set.class); HashSet<String> skus = new HashSet<>(); skus.add(sku); Object requestId = m.invoke(null, skus); skuDetailsRequestMap.put(requestId.toString(), requestId); synchronized (requestId) { requestId.wait(); } skuDetailsRequestMap.remove(requestId.toString()); JSONObject ret = new JSONObject(); ret.put("price_string", skuPriceMap.get(sku)); return ret; } catch (Exception e) { Log.e(LOG_TAG, "Reflection error: " + Log.getStackTraceString(e)); Teak.sdkRaven.reportException(e); } return null; }
From source file:net.urlgrey.mythpodcaster.transcode.GlobalTranscodeAndCleanupTaskImpl.java
private void doWork() { status.setMode(StatusMode.TRANSCODING); status.setCurrentTriggerStart(new Date()); status.setCurrentTranscodeStart(null); status.clearDisplayFields();//w w w.jav a 2 s . c o m final List<FeedSubscriptionItem> purgeList = new ArrayList<FeedSubscriptionItem>(); // retrieve series subscriptions List<FeedSubscriptionItem> subscriptions = subscriptionsDao.findSubscriptions(); // iterate over each series for (FeedSubscriptionItem subscription : subscriptions) { // parse the XML-encoded RSS Feed into a Java object final SyndFeed feed; try { feed = feedFileAccessor.readFeed(subscription.getSeriesId(), subscription.getTranscodeProfile(), subscription.getTitle()); } catch (IOException e) { LOGGER.error("Continuing, error reading feed for recordId[" + subscription.getSeriesId() + "]", e); continue; } if (subscription.isActive() == false) { // if the series is inactive, then delete the feed, it's transcoded files, and the // subscription entry feedFileAccessor.purgeFeed(subscription.getSeriesId(), subscription.getTranscodeProfile(), feed); purgeList.add(subscription); } } // purge those subscriptions marked for deletion subscriptionsDao.purge(purgeList); // refresh the list of subscriptions subscriptions = subscriptionsDao.findSubscriptions(); // iterate over each series to identify those requiring transcoding for (FeedSubscriptionItem subscription : subscriptions) { LOGGER.debug("Processing feed subscription for recordId[" + subscription.getSeriesId() + "]"); // parse the XML-encoded RSS Feed into a Java object final SyndFeed feed; try { feed = feedFileAccessor.readFeed(subscription.getSeriesId(), subscription.getTranscodeProfile(), subscription.getTitle()); } catch (IOException e) { LOGGER.error("Continuing, error reading feed for recordId[" + subscription.getSeriesId() + "]", e); continue; } Runnable task = (Runnable) this.applicationContext.getBean("feedTranscodingTask", new Object[] { subscription, feed }); executor.execute(task); } // add a task to the execution queue that denotes the end of the queue final Object semaphore = new Object(); executor.execute(new TranscodingCompletionTaskImpl(semaphore)); try { synchronized (semaphore) { semaphore.wait(); } // check the queue and perform a manual poll if there are still tasks, // as in the case of parallel task execution (2 or more threads) while (executor.getActiveCount() > 0) { try { Thread.sleep(QUEUE_POLLING_FREQUENCY); } catch (InterruptedException e) { LOGGER.warn("Thread was interrupted while polling for thread-pool to finish work"); } } } catch (InterruptedException e) { LOGGER.warn("Thread was interrupted while waiting for thread-pool to finish work"); } status.setMode(StatusMode.IDLE); status.setCurrentTriggerStart(null); status.setCurrentTranscodeStart(null); status.clearDisplayFields(); }
From source file:org.rifidi.emulator.reader.command.controller.abstract_.AbstractSuspendedCommandControllerPowerState.java
/** * Waits until resumed to process the command. If the turnOff method is * invoked while this is waiting, this method will return null. * /*ww w .j ava 2 s .c om*/ * @see org.rifidi.emulator.reader.command.controller.CommandControllerPowerState#processCommand(byte[], * org.rifidi.emulator.reader.command.controller.CommandController) */ public ArrayList<Object> processCommand(byte[] command, CommandController controller) throws CommandControllerException { ArrayList<Object> retList = null; AbstractCommandController abstractController = (AbstractCommandController) controller; /* Synchronize on the passed processor's suspension lock */ Object lock = abstractController.getSuspensionLock(); synchronized (lock) { /* Keep waiting while this is suspended but not interrupted */ while (abstractController.isSuspended() && !abstractController.isInterrupted()) { try { lock.wait(); } catch (InterruptedException e) { /* Do nothing */ } } /* Check to see why this dropped out of the loop */ if (!abstractController.isInterrupted()) { /* Resumed -- allow processCommand to continue */ abstractController.getCurOperatingState().processCommand(command, controller); } else { throw new CommandControllerException("Command processing interrupted while suspended."); } } /* Return the command response */ return retList; }
From source file:org.openengsb.connector.maven.internal.MavenServiceTest.java
private Thread startWaiterThread(final Object sync) { final Thread thread = new Thread() { @Override// w w w . j a v a2 s. co m public void run() { synchronized (sync) { try { sync.wait(); } catch (InterruptedException e) { throw new RuntimeException(e); } } }; }; thread.start(); return thread; }
From source file:me.st28.flexseries.flexcore.player.PlayerManager.java
@EventHandler(priority = EventPriority.HIGHEST) public void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent e) { if (e.getLoginResult() != Result.ALLOWED) return;//from w w w . j a va2 s . c o m final UUID uuid = e.getUniqueId(); if (uuid == null) return; handledPlayers.add(uuid); // Begin loading PlayerLoadCycle cycle = new PlayerLoadCycle(uuid, e.getName(), loadTimeout); final Object loadLock = new Object(); cycle.startLoading(loadLock); synchronized (loadLock) { while (cycle.getLoadResult() == null) { try { loadLock.wait(); } catch (InterruptedException ex) { break; } } } if (!cycle.getLoadResult().isSuccess()) { e.disallow(Result.KICK_OTHER, cycle.getLoadResult().getFailMessage()); } else { e.allow(); cachedCycles.put(uuid, cycle); } }