/** {@inheritDoc} */ @Override protected Collection<E> dequeue0(int cnt) { WindowHolder tup = ref.get(); AtomicInteger size = tup.size(); Collection<T> evts = tup.collection(); Collection<E> resCol = new ArrayList<>(cnt); while (true) { int curSize = size.get(); if (curSize > 0) { if (size.compareAndSet(curSize, curSize - 1)) { E res = pollInternal(evts, tup.set()); if (res != null) { resCol.add(res); if (resCol.size() >= cnt) return resCol; } else { size.incrementAndGet(); return resCol; } } } else return resCol; } }
/** * Poll evicted internal implementation. * * @return Evicted element. */ @Nullable private E pollEvictedInternal() { WindowHolder tup = ref.get(); AtomicInteger size = tup.size(); while (true) { int curSize = size.get(); if (curSize > maxSize) { if (size.compareAndSet(curSize, curSize - 1)) { E evt = pollInternal(tup.collection(), tup.set()); if (evt != null) return evt; else { // No actual events in queue, it means that other thread is just adding event. // return null as it is a concurrent add call. size.incrementAndGet(); return null; } } } else return null; } }
/* * Launches against the agent */ public void testSimpleLauncher() throws Exception { Project project = workspace.getProject("p1"); Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun")); bndrun.setProperty("-runpath", "biz.aQute.remote.launcher"); bndrun.setProperty("-runbundles", "bsn-1,bsn-2"); bndrun.setProperty("-runremote", "test"); final RemoteProjectLauncherPlugin pl = (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher(); pl.prepare(); final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger exitCode = new AtomicInteger(-1); List<? extends RunSession> sessions = pl.getRunSessions(); assertEquals(1, sessions.size()); final RunSession session = sessions.get(0); Thread t = new Thread("test-launch") { public void run() { try { exitCode.set(session.launch()); } catch (Exception e) { e.printStackTrace(); } finally { latch.countDown(); } } }; t.start(); Thread.sleep(500); for (Bundle b : context.getBundles()) { System.out.println(b.getLocation()); } assertEquals(4, context.getBundles().length); String p1 = t1.getAbsolutePath(); System.out.println(p1); assertNotNull(context.getBundle(p1)); assertNotNull(context.getBundle(t2.getAbsolutePath())); pl.cancel(); latch.await(); assertEquals(-3, exitCode.get()); bndrun.close(); }
private void reset(int op) { done(); _buffer.reset(); set(_buffer); _id = ID.getAndIncrement(); writeInt(0); // length: will set this later writeInt(_id); writeInt(0); // response to writeInt(op); }
public ContinuousChangesFeed(String dbName, HttpResponse httpResponse) { this.httpResponse = httpResponse; try { reader = new BufferedReader(new InputStreamReader(httpResponse.getContent(), "UTF-8")); thread.setName( String.format( "ektorp-%s-changes-listening-thread-%s", dbName, THREAD_COUNT.getAndIncrement())); thread.start(); } catch (UnsupportedEncodingException e) { throw Exceptions.propagate(e); } }
/** * Tests that failover don't pick local node if it has been excluded from topology. * * @throws Exception If failed. */ @SuppressWarnings({"WaitNotInLoop", "UnconditionalWait", "unchecked"}) public void testFailoverTopology() throws Exception { try { Grid grid1 = startGrid(1); Grid grid2 = startGrid(2); assert grid1 != null; assert grid2 != null; grid1.compute().localDeployTask(JobTask.class, JobTask.class.getClassLoader()); try { GridComputeTaskFuture<String> fut; synchronized (mux) { fut = grid1.compute().execute(JobTask.class, null); mux.wait(); } stopAndCancelGrid(2); String res = fut.get(); info("Task result: " + res); } catch (GridException e) { info("Got unexpected grid exception: " + e); } info("Failed over: " + failCnt.get()); assert failCnt.get() == 1 : "Invalid fail over counter [expected=1, actual=" + failCnt.get() + ']'; } finally { stopGrid(1); // Stopping stopped instance just in case. stopGrid(2); } }
void append(String db, WriteConcern c) { _id = ID.getAndIncrement(); int loc = size(); writeInt(0); // will set this later writeInt(_id); writeInt(0); // response to writeInt(2004); _appendQuery(0, db + ".$cmd", 0, -1, c.getCommand(), null); _buf.writeInt(loc, size() - loc); }
private DarkBotMCSpambot( DarkBot darkBot, String server, String username, String password, String sessionId, String loginProxy, String proxy, String owner) { synchronized (bots) { bots.add(this); // slotsTaken.incrementAndGet(); synchronized (slotsTaken) { slotsTaken.notifyAll(); } } MinecraftBotData.Builder builder = MinecraftBotData.builder(); // botData.nickname = ""; // for(int i = 0; i < 10; i++) // botData.nickname += alphas[random.nextInt(alphas.length)]; if (proxy != null && !proxy.isEmpty()) { int port = 80; ProxyType type = ProxyType.SOCKS; if (proxy.contains(":")) { String[] parts = proxy.split(":"); proxy = parts[0]; port = Integer.parseInt(parts[1]); if (parts.length > 2) type = ProxyType.values()[Integer.parseInt(parts[2]) - 1]; } builder.withSocksProxy(new ProxyData(proxy, port, type)); this.proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxy, port)); } if (loginProxy != null && !loginProxy.isEmpty()) { int port = 80; if (loginProxy.contains(":")) { String[] parts = loginProxy.split(":"); loginProxy = parts[0]; port = Integer.parseInt(parts[1]); } builder.withHttpProxy(new ProxyData(loginProxy, port, ProxyType.HTTP)); this.loginProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(loginProxy, port)); } builder.withUsername(username); if (sessionId != null) builder.withSessionId(sessionId); else builder.withPassword(password); if (server != null && !server.isEmpty()) { int port = 25565; if (server.contains(":")) { String[] parts = server.split(":"); server = parts[0]; port = Integer.parseInt(parts[1]); } builder.withServer(server).withPort(port); } else throw new IllegalArgumentException("Unknown server!"); this.owner = owner; MinecraftBotData botData = builder.build(); System.setProperty("socksProxyHost", ""); System.setProperty("socksProxyPort", ""); System.out.println("[" + username + "] Connecting..."); bot = new MinecraftBot(darkBot, botData); bot.setMovementDisabled(true); connectionHandler = bot.getConnectionHandler(); Session session = bot.getSession(); // System.gc(); System.out.println("[" + username + "] Done! (" + amountJoined.incrementAndGet() + ")"); bot.getEventManager().registerListener(this); bot.getGameHandler().registerListener(this); long lastShoutTime = System.currentTimeMillis(); while (bot.isConnected()) { if (die) { connectionHandler.sendPacket(new Packet255KickDisconnect("Goodbye")); return; } try { Thread.sleep(3000 + random.nextInt(1000)); } catch (InterruptedException exception) { exception.printStackTrace(); } if (!bot.hasSpawned()) continue; connectionHandler.sendPacket(new Packet0KeepAlive(random.nextInt())); if (spamMessage == null || !canSpam) continue; String message = spamMessage; if (message.contains("%skill")) message = message.replace("%skill", skills[nextSkill++]); if (nextSkill >= skills.length) nextSkill = 0; if (message.contains("%bot")) { synchronized (bots) { message = message.replace( "%bot", bots.get(nextBot > bots.size() ? (nextBot = 0) * 0 : nextBot++) .bot .getSession() .getUsername()); } } if (message.contains("%spamlist")) message = message.replace("%spamlist", spamList[nextSpamList++]); if (nextSpamList >= spamList.length) nextSpamList = 0; if (message.contains("%rnd")) { int length = 1; int index = message.indexOf("%rnd") + "%rnd".length(); int lastIndex; for (lastIndex = index; lastIndex < message.length(); lastIndex++) if (Character.isDigit(message.charAt(lastIndex))) lastIndex++; else break; if (lastIndex > message.length()) lastIndex--; try { System.out.println(index + "," + lastIndex + "," + message.length()); length = Integer.parseInt(message.substring(index, lastIndex)); } catch (Exception exception) { } String randomChars = ""; for (int i = 0; i < length; i++) randomChars += alphas[random.nextInt(alphas.length)]; message = message.replace("%rnd", randomChars); } if (message.contains("%msg")) message = "/msg " + msgChars[nextMsgChar++] + " " + message.replace("%msg", ""); if (message.contains("%ernd")) { message = message.replace("%ernd", ""); int extraMessageLength = 15 + random.nextInt(6); message = message.substring(0, Math.min(100 - extraMessageLength, message.length())) + " ["; extraMessageLength -= 3; for (int i = 0; i < extraMessageLength; i++) message += alphas[random.nextInt(alphas.length)]; message += "]"; } else message = message.substring(0, Math.min(100, message.length())); connectionHandler.sendPacket(new Packet3Chat(message)); } synchronized (bots) { bots.remove(this); } amountJoined.decrementAndGet(); slotsTaken.decrementAndGet(); synchronized (slotsTaken) { slotsTaken.notifyAll(); } }