use of org.eclipse.jetty.util.ConcurrentHashSet in project jetty.project by eclipse.
the class AnnotationConfiguration method createServletContainerInitializerAnnotationHandlers.
public void createServletContainerInitializerAnnotationHandlers(WebAppContext context, List<ServletContainerInitializer> scis) throws Exception {
if (scis == null || scis.isEmpty())
// nothing to do
return;
List<ContainerInitializer> initializers = new ArrayList<ContainerInitializer>();
context.setAttribute(CONTAINER_INITIALIZERS, initializers);
for (ServletContainerInitializer service : scis) {
HandlesTypes annotation = service.getClass().getAnnotation(HandlesTypes.class);
ContainerInitializer initializer = null;
if (annotation != null) {
//There is a HandlesTypes annotation on the on the ServletContainerInitializer
Class<?>[] classes = annotation.value();
if (classes != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("HandlesTypes {} on initializer {}", Arrays.asList(classes), service.getClass());
}
initializer = new ContainerInitializer(service, classes);
//process the whole class hierarchy to satisfy the ServletContainerInitializer
if (context.getAttribute(CLASS_INHERITANCE_MAP) == null) {
//MultiMap<String> map = new MultiMap<>();
ConcurrentHashMap<String, ConcurrentHashSet<String>> map = new ClassInheritanceMap();
context.setAttribute(CLASS_INHERITANCE_MAP, map);
_classInheritanceHandler = new ClassInheritanceHandler(map);
}
for (Class<?> c : classes) {
//register a handler for it
if (c.isAnnotation()) {
if (LOG.isDebugEnabled())
LOG.debug("Registering annotation handler for " + c.getName());
_containerInitializerAnnotationHandlers.add(new ContainerInitializerAnnotationHandler(initializer, c));
}
}
} else {
initializer = new ContainerInitializer(service, null);
if (LOG.isDebugEnabled())
LOG.debug("No classes in HandlesTypes on initializer " + service.getClass());
}
} else {
initializer = new ContainerInitializer(service, null);
if (LOG.isDebugEnabled())
LOG.debug("No HandlesTypes annotation on initializer " + service.getClass());
}
initializers.add(initializer);
}
//add a bean to the context which will call the servletcontainerinitializers when appropriate
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter) context.getAttribute(CONTAINER_INITIALIZER_STARTER);
if (starter != null)
throw new IllegalStateException("ServletContainerInitializersStarter already exists");
starter = new ServletContainerInitializersStarter(context);
context.setAttribute(CONTAINER_INITIALIZER_STARTER, starter);
context.addBean(starter, true);
}
use of org.eclipse.jetty.util.ConcurrentHashSet in project ignite by apache.
the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testClientMetadataInitialization.
/**
* @throws Exception If failed.
*/
public void testClientMetadataInitialization() throws Exception {
startGrids(2);
final AtomicBoolean stop = new AtomicBoolean();
final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
IgniteInternalFuture<?> fut;
try {
// Update binary metadata concurrently with client nodes start.
fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteBinary binaries = ignite(0).binary();
IgniteCache<Object, Object> cache = ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 1000; i++) {
log.info("Iteration: " + i);
String type = "binary-type-" + i;
allTypes.add(type);
for (int f = 0; f < 10; f++) {
BinaryObjectBuilder builder = binaries.builder(type);
String fieldName = "f" + f;
builder.setField(fieldName, i);
cache.put(rnd.nextInt(0, 100_000), builder.build());
if (f % 100 == 0)
log.info("Put iteration: " + f);
}
if (stop.get())
break;
}
return null;
}
}, 5, "update-thread");
} finally {
stop.set(true);
}
client = true;
startGridsMultiThreaded(2, 5);
fut.get();
assertFalse(allTypes.isEmpty());
log.info("Expected binary types: " + allTypes.size());
assertEquals(7, ignite(0).cluster().nodes().size());
for (int i = 0; i < 7; i++) {
log.info("Check metadata on node: " + i);
boolean client = i > 1;
assertEquals((Object) client, ignite(i).configuration().isClientMode());
IgniteBinary binaries = ignite(i).binary();
Collection<BinaryType> metaCol = binaries.types();
assertEquals(allTypes.size(), metaCol.size());
Set<String> names = new HashSet<>();
for (BinaryType meta : metaCol) {
info("Binary type: " + meta);
assertTrue(names.add(meta.typeName()));
assertNull(meta.affinityKeyFieldName());
assertEquals(10, meta.fieldNames().size());
}
assertEquals(allTypes.size(), names.size());
}
}
use of org.eclipse.jetty.util.ConcurrentHashSet in project ignite by apache.
the class IgniteCacheClientNodeChangingTopologyTest method multinode.
/**
* @param atomicityMode Atomicity mode cache.
* @param testType Test type.
* @throws Exception If failed.
*/
private void multinode(CacheAtomicityMode atomicityMode, final TestType testType) throws Exception {
ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(PARTITIONED);
ccfg.setBackups(1);
ccfg.setAtomicityMode(atomicityMode);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setRebalanceMode(SYNC);
final int SRV_CNT = 4;
for (int i = 0; i < SRV_CNT; i++) startGrid(i);
final int CLIENT_CNT = 4;
final List<Ignite> clients = new ArrayList<>();
client = true;
for (int i = 0; i < CLIENT_CNT; i++) {
Ignite ignite = startGrid(SRV_CNT + i);
assertTrue(ignite.configuration().isClientMode());
clients.add(ignite);
}
final AtomicBoolean stop = new AtomicBoolean();
final AtomicInteger threadIdx = new AtomicInteger(0);
final int THREADS = CLIENT_CNT * 3;
final ConcurrentHashSet<Integer> putKeys = new ConcurrentHashSet<>();
IgniteInternalFuture<?> fut;
try {
fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int clientIdx = threadIdx.getAndIncrement() % CLIENT_CNT;
Ignite ignite = clients.get(clientIdx);
assertTrue(ignite.configuration().isClientMode());
Thread.currentThread().setName("update-thread-" + ignite.name());
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
boolean useTx = testType == TestType.OPTIMISTIC_TX || testType == TestType.OPTIMISTIC_SERIALIZABLE_TX || testType == TestType.PESSIMISTIC_TX;
if (useTx || testType == TestType.LOCK) {
assertEquals(TRANSACTIONAL, cache.getConfiguration(CacheConfiguration.class).getAtomicityMode());
}
ThreadLocalRandom rnd = ThreadLocalRandom.current();
int cntr = 0;
while (!stop.get()) {
TreeMap<Integer, Integer> map = new TreeMap<>();
for (int i = 0; i < 100; i++) {
Integer key = rnd.nextInt(0, 1000);
map.put(key, rnd.nextInt());
}
try {
if (testType == TestType.LOCK) {
Lock lock = cache.lockAll(map.keySet());
lock.lock();
lock.unlock();
} else {
if (useTx) {
IgniteTransactions txs = ignite.transactions();
TransactionConcurrency concurrency = testType == TestType.PESSIMISTIC_TX ? PESSIMISTIC : OPTIMISTIC;
TransactionIsolation isolation = testType == TestType.OPTIMISTIC_SERIALIZABLE_TX ? SERIALIZABLE : REPEATABLE_READ;
try (Transaction tx = txs.txStart(concurrency, isolation)) {
cache.putAll(map);
tx.commit();
}
} else
cache.putAll(map);
putKeys.addAll(map.keySet());
}
} catch (CacheException | IgniteException e) {
log.info("Operation failed, ignore: " + e);
}
if (++cntr % 100 == 0)
log.info("Iteration: " + cntr);
if (updateBarrier != null)
updateBarrier.await();
}
return null;
}
}, THREADS, "update-thread");
long stopTime = System.currentTimeMillis() + 60_000;
while (System.currentTimeMillis() < stopTime) {
boolean restartClient = ThreadLocalRandom.current().nextBoolean();
Integer idx = null;
if (restartClient) {
log.info("Start client node.");
client = true;
IgniteEx ignite = startGrid(SRV_CNT + CLIENT_CNT);
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
} else {
idx = ThreadLocalRandom.current().nextInt(0, SRV_CNT);
log.info("Stop server node: " + idx);
stopGrid(idx);
}
updateBarrier = new CyclicBarrier(THREADS + 1, new Runnable() {
@Override
public void run() {
updateBarrier = null;
}
});
try {
updateBarrier.await(30_000, TimeUnit.MILLISECONDS);
} catch (TimeoutException ignored) {
log.error("Failed to wait for update.");
for (Ignite ignite : G.allGrids()) ((IgniteKernal) ignite).dumpDebugInfo();
U.dumpThreads(log);
CyclicBarrier barrier0 = updateBarrier;
if (barrier0 != null)
barrier0.reset();
fail("Failed to wait for update.");
}
U.sleep(500);
if (restartClient) {
log.info("Stop client node.");
stopGrid(SRV_CNT + CLIENT_CNT);
} else {
log.info("Start server node: " + idx);
client = false;
startGrid(idx);
}
updateBarrier = new CyclicBarrier(THREADS + 1, new Runnable() {
@Override
public void run() {
updateBarrier = null;
}
});
try {
updateBarrier.await(30_000, TimeUnit.MILLISECONDS);
} catch (TimeoutException ignored) {
log.error("Failed to wait for update.");
for (Ignite ignite : G.allGrids()) ((IgniteKernal) ignite).dumpDebugInfo();
U.dumpThreads(log);
CyclicBarrier barrier0 = updateBarrier;
if (barrier0 != null)
barrier0.reset();
fail("Failed to wait for update.");
}
U.sleep(500);
}
} finally {
stop.set(true);
}
fut.get(30_000);
if (testType != TestType.LOCK)
checkData(null, putKeys, grid(SRV_CNT).cache(DEFAULT_CACHE_NAME), SRV_CNT + CLIENT_CNT);
}
use of org.eclipse.jetty.util.ConcurrentHashSet in project sling by apache.
the class VotingHandlerTest method doTestConcurrentVotes.
public void doTestConcurrentVotes(int votingsLoopCnt, int perVotingInnerLoopCnt, VotingHandler... votingHandler) throws Exception {
config.setHeartbeatInterval(999);
config.setHeartbeatTimeout(120);
for (VotingHandler handler : votingHandler) {
handler.activate(null);
}
int[] totals = new int[votingHandler.length];
List<Map<VotingDetail, Integer>> totalDetails = new LinkedList<Map<VotingDetail, Integer>>();
for (int i = 0; i < votingHandler.length; i++) {
HashMap<VotingDetail, Integer> d = new HashMap<VotingHandler.VotingDetail, Integer>();
totalDetails.add(d);
}
String[] slingIds = new String[votingHandler.length];
for (int k = 0; k < votingHandler.length; k++) {
slingIds[k] = (String) PrivateAccessor.getField(votingHandler[k], "slingId");
}
for (int i = 0; i < votingsLoopCnt; i++) {
// large voting loop
logger.info("testConcurrentVotes: loop i=" + i + ", votingHandler.cnt=" + votingHandler.length);
for (int k = 0; k < votingHandler.length; k++) {
heartbeat(slingIds[k]);
}
for (int k = 0; k < votingHandler.length; k++) {
String initiatorId = (String) PrivateAccessor.getField(votingHandler[k], "slingId");
VotingView voting = newVoting(initiatorId, slingIds);
assertNotNull(voting);
}
Semaphore ready = new Semaphore(0);
Semaphore go = new Semaphore(0);
Semaphore done = new Semaphore(0);
Set<Throwable> e = new ConcurrentHashSet<Throwable>();
boolean success = false;
List<List<VotingDetail>> detailList = new LinkedList<List<VotingDetail>>();
for (int k = 0; k < votingHandler.length; k++) {
detailList.add(new LinkedList<VotingHandler.VotingDetail>());
}
for (int j = 0; j < perVotingInnerLoopCnt; j++) {
logger.info("testConcurrentVotes: loop i=" + i + ", votingHandler.cnt=" + votingHandler.length + ", j=" + j);
for (int k = 0; k < votingHandler.length; k++) {
logger.info("testConcurrentVotes: <heartbeat for slingId,k=" + k + "> loop i=" + i + ", votingHandler.cnt=" + votingHandler.length + ", j=" + j);
heartbeat(slingIds[k]);
logger.info("testConcurrentVotes: <asyncVote for slingId,k=" + k + "> loop i=" + i + ", votingHandler.cnt=" + votingHandler.length + ", j=" + j);
asyncVote("k=" + k, votingHandler[k], detailList.get(k), ready, go, done, e);
}
assertTrue("threads were not ready within 30sec", ready.tryAcquire(votingHandler.length, 30, TimeUnit.SECONDS));
// both are now ready, so lets go
logger.info("testConcurrentVotes: GO loop i=" + i + ", votingHandler.cnt=" + votingHandler.length + ", j=" + j);
go.release(votingHandler.length);
assertTrue("threads were not done within 120sec", done.tryAcquire(votingHandler.length, 120, TimeUnit.SECONDS));
if (e.size() != 0) {
fail("Got exceptions: " + e.size() + ", first: " + e.iterator().next());
}
int promotionTotalCount = 0;
int noTotalCount = 0;
for (int k = 0; k < votingHandler.length; k++) {
int promotedCnt = count(detailList.get(k), VotingDetail.PROMOTED);
int noCnt = count(detailList.get(k), VotingDetail.VOTED_NO);
totals[k] += promotedCnt;
promotionTotalCount += promotedCnt;
noTotalCount += noCnt;
}
if (promotionTotalCount == 0) {
// should have 1 promotionTotalCount, if not, repeat
continue;
} else if (promotionTotalCount > 1) {
fail("more than 1 promoted views: " + promotionTotalCount);
} else if (noTotalCount < votingHandler.length - 1) {
// should have votingHandler.length-1 no votes, if not, repeat
continue;
} else {
// done
success = true;
break;
}
}
assertTrue("did not promote within " + perVotingInnerLoopCnt + " loops", success);
for (int k = 0; k < votingHandler.length; k++) {
add(detailList.get(k), totalDetails.get(k));
}
}
StringBuffer sb = new StringBuffer();
for (int k = 0; k < votingHandler.length; k++) {
sb.append(" - by slingId");
sb.append(k + 1);
sb.append(": ");
sb.append(totals[k]);
}
logger.info("testConcurrentVotes: promoted " + sb);
int totalPromotion = 0;
for (int k = 0; k < votingHandler.length; k++) {
for (Map.Entry<VotingDetail, Integer> anEntry : totalDetails.get(k).entrySet()) {
logger.info("testConcurrentVotes: slingId" + (k + 1) + ", detail=" + anEntry.getKey() + ", value=" + anEntry.getValue());
}
// SLING-5244 : cannot assume that we have '(votingHandler.length-1) * votingsLoopCnt'
// because: it can happen that a voting concludes within one j-loop above:
// that is the case when the instance that does not initiate the vote comes first, then
// the initiator - in that case the initiator finds an already completed vote - and it
// will then not do any no-votes ..
// so .. this check is a) not possible and b) just also not necessary, cos
// we already make sure that we at least get 'votingHandler.length-1' no votes in the j-loop
// and that is precise enough. so as unfortuante as it is, we can't make below assertion..
// unless we do more white-box-assertions into analyzeVotings, which is probably not helping
// test-stability either..
// Integer noVotes = totalDetails.get(k).get(VotingDetail.VOTED_NO);
// int expected = (votingHandler.length-1) * votingsLoopCnt;
// if (expected>0) {
// assertEquals(expected, (int)noVotes);
// }
final Map<VotingDetail, Integer> map = totalDetails.get(k);
final Integer i = map.get(VotingDetail.PROMOTED);
if (i != null) {
totalPromotion += i;
}
}
assertEquals(votingsLoopCnt, totalPromotion);
}
use of org.eclipse.jetty.util.ConcurrentHashSet in project ignite by apache.
the class TcpDiscoveryRestartTest method testRestart.
/**
* @throws Exception If failed.
*/
public void testRestart() throws Exception {
err = new AtomicReference<>();
final int NODE_CNT = 3;
startGrids(NODE_CNT);
final ConcurrentHashSet<UUID> nodeIds = new ConcurrentHashSet<>();
final AtomicInteger id = new AtomicInteger(NODE_CNT);
final IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int nodeIdx = id.getAndIncrement();
for (int i = 0; i < 10 && err.get() == null; i++) {
Ignite ignite = startGrid(nodeIdx);
UUID nodeId = ignite.cluster().localNode().id();
if (!nodeIds.add(nodeId))
failed("Duplicated node ID: " + nodeId);
stopGrid(nodeIdx);
}
return null;
}
}, 5, "restart-thread");
IgniteInternalFuture<?> loadFut = GridTestUtils.runMultiThreadedAsync(new Callable<Long>() {
@Override
public Long call() throws Exception {
long dummyRes = 0;
List<String> list = new ArrayList<>();
while (!fut.isDone()) {
for (int i = 0; i < 100; i++) {
String str = new String(new byte[i]);
list.add(str);
dummyRes += str.hashCode();
}
if (list.size() > 1000_000) {
list = new ArrayList<>();
System.gc();
}
}
return dummyRes;
}
}, 2, "test-load");
fut.get();
loadFut.get();
assertNull(err.get());
for (int i = 0; i < NODE_CNT; i++) {
Ignite ignite = ignite(i);
TestEventListener lsnr = (TestEventListener) F.firstKey(ignite.configuration().getLocalEventListeners());
assertNotNull(lsnr);
for (UUID nodeId : nodeIds) lsnr.checkEvents(nodeId);
}
}
Aggregations