Example usage for java.util Queue remove

List of usage examples for java.util Queue remove

Introduction

In this page you can find the example usage for java.util Queue remove.

Prototype

boolean remove(Object o);

Source Link

Document

Removes a single instance of the specified element from this collection, if it is present (optional operation).

Usage

From source file:com.clustercontrol.jobmanagement.util.JobMultiplicityCache.java

/**
 * waitQueue??//w w  w. j a v a2 s.c  o  m
 *
 * ???????????????
 * waitQueue?????
 *
 * ??????waitQueue??????
 * ????????????
 *
 * @param pk
 */
public static void removeWait(JobSessionNodeEntityPK pk) {
    try {
        _lock.writeLock();

        HashMap<String, Queue<JobSessionNodeEntityPK>> waitingCache = getWaitingCache();

        Queue<JobSessionNodeEntityPK> waitingQueue = waitingCache.get(pk.getFacilityId());
        if (waitingQueue != null) {
            if (waitingQueue.remove(pk)) {
                m_log.info("removeWait " + pk);
                storeWaitingCache(waitingCache);
            }
        }
    } finally {
        _lock.writeUnlock();
    }
}

From source file:com.clustercontrol.jobmanagement.util.JobMultiplicityCache.java

/**
 * status?100(StatusConstant.TYPE_RUNNING)????????????
 *
 * ???runningQueue???????/*from   w w w .  j  av  a2s .  co m*/
 * ?????????????kick
 * @param pk
 */
public static boolean fromRunning(JobSessionNodeEntityPK pk) {
    m_log.info("fromRunning " + pk);

    String facilityId = pk.getFacilityId();

    try {
        _lock.writeLock();

        HashMap<String, Queue<JobSessionNodeEntityPK>> runningCache = getRunningCache();

        Queue<JobSessionNodeEntityPK> runningQueue = runningCache.get(facilityId);
        if (runningQueue == null) {
            m_log.warn("fromRunning " + pk);
            return false;
        }

        if (runningQueue.remove(pk)) { //// runningQueue?
            storeRunningCache(runningCache);
        } else {
            // ????????
            // (??)??????????
            m_log.info("fromRunning(). from not-running to stop : " + pk);
        }

        if (m_log.isDebugEnabled()) {
            for (JobSessionNodeEntityPK q : runningQueue) {
                m_log.debug("fromRunning runningQueue : " + q);
            }
        }

        // ?facilityID?????
        kick(facilityId);
    } finally {
        _lock.writeUnlock();
    }
    return true;
}

From source file:com.sishuok.chapter3.web.controller.chat.MsgPublisher.java

public DeferredResult<String> startAsync(final String username) {
    final DeferredResult<String> result = new DeferredResult<String>(30L * 1000, null);

    final Runnable removeDeferredResultRunnable = new Runnable() {
        @Override//from ww w . java 2 s .  c  o  m
        public void run() {
            Queue<DeferredResult<String>> queue = usernameToDeferredResultMap.get(username);
            if (queue != null) {
                queue.remove(result);
            }
        }
    };
    result.onCompletion(removeDeferredResultRunnable);
    result.onTimeout(removeDeferredResultRunnable);

    //????
    Queue<DeferredResult<String>> queue = usernameToDeferredResultMap.get(username);
    if (queue == null) {
        queue = new ConcurrentLinkedDeque();
        usernameToDeferredResultMap.put(username, queue);
    }
    queue.add(result);

    return result;
}

From source file:asia.stampy.server.listener.subscription.AbstractAcknowledgementListenerAndInterceptor.java

private void clearMessageAck(String messageId, HostPort hostPort) {
    Queue<String> ids = messages.get(hostPort);
    if (ids == null)
        return;//  ww w. j ava2s  .c om

    ids.remove(messageId);
}

From source file:com.github.wolfdogs.kemono.util.event.RootEventManager.java

private void removeHandler(HandlerEntry entry) {
    if (entry == null)
        return;/*  w w  w.j  av a2 s  . com*/

    Class<? extends Event> type = entry.getType();
    Object relatedObject = entry.getRelatedObject();

    Map<Object, Queue<HandlerEntry>> objectEntriesMap = handlerEntryContainersMap.get(type);
    if (objectEntriesMap == null)
        return;

    Queue<HandlerEntry> entries = objectEntriesMap.get(relatedObject);
    if (entries == null)
        return;

    entries.remove(entry);

    if (entries.size() == 0)
        objectEntriesMap.remove(relatedObject);
    if (objectEntriesMap.size() == 0)
        handlerEntryContainersMap.remove(type);
}

From source file:asia.stampy.server.listener.subscription.AbstractAcknowledgementListenerAndInterceptor.java

private void startTimerTask(final HostPort hostPort, final String ack) {
    TimerTask task = new TimerTask() {

        @Override/*from   w  ww  . jav a  2 s. c o  m*/
        public void run() {
            Queue<String> q = messages.get(hostPort);
            if (q == null || !q.contains(ack))
                return;

            getHandler().noAcknowledgementReceived(ack);
            q.remove(ack);
        }
    };

    ackTimer.schedule(task, getAckTimeoutMillis());
}

From source file:com.taobao.metamorphosis.gregor.slave.OrderedThreadPoolExecutor.java

/**
 * {@inheritDoc}//from w  w  w  .j a  va2s.com
 */
@Override
public boolean remove(final Runnable task) {
    this.checkTaskType(task);
    final IoEvent event = (IoEvent) task;
    final IoCatalog ioCatalog = event.getIoCatalog();
    final TasksQueue sessionTasksQueue = (TasksQueue) ioCatalog.connection
            .getAttribute(this.getCatalog(ioCatalog));
    final Queue<Runnable> tasksQueue = sessionTasksQueue.tasksQueue;
    if (sessionTasksQueue == null) {
        return false;
    }

    boolean removed;

    synchronized (tasksQueue) {
        removed = tasksQueue.remove(task);
    }

    return removed;
}

From source file:cosmos.sql.TestSql.java

@Test
public void testNoLimit() throws SQLException {
    loadDriverClass();//  ww w. j a  va  2  s.c o m
    Connection connection = null;
    Statement statement = null;
    try {
        Properties info = new Properties();
        info.put("url", JDBC_URL);
        info.put("user", USER);
        info.put("password", PASSWORD);
        connection = DriverManager.getConnection("jdbc:accumulo:cosmos//localhost", info);
        statement = connection.createStatement();
        final ResultSet resultSet = statement.executeQuery(
                "select \"PAGE_ID\" from \"" + CosmosDriver.COSMOS + "\".\"" + meataData.uuid() + "\"");

        final ResultSetMetaData metaData = resultSet.getMetaData();
        final int columnCount = metaData.getColumnCount();

        assertEquals(columnCount, 1);

        int resultsFound = 0;
        SortedSet<String> sets = Sets.newTreeSet();
        for (int i = 0; i < 10; i++) {
            sets.add(Integer.valueOf(i).toString());
        }
        Queue<String> values = Lists.newLinkedList(sets);

        while (resultSet.next()) {
            assertEquals(metaData.getColumnName(1), "PAGE_ID");
            @SuppressWarnings("unchecked")
            List<Entry<Column, RecordValue<?>>> sValues = (List<Entry<Column, RecordValue<?>>>) resultSet
                    .getObject("PAGE_ID");
            assertEquals(sValues.size(), 1);
            RecordValue<?> onlyValue = sValues.iterator().next().getValue();
            assertEquals(onlyValue.visibility().toString(), "[en]");
            values.remove(onlyValue.value());
            resultsFound++;

        }

        assertEquals(resultsFound, 10);
        assertEquals(values.size(), 0);
    } finally {
        close(connection, statement);
    }
}

From source file:com.netflix.curator.framework.recipes.locks.TestReaper.java

@Test
public void testSparseUseNoReap() throws Exception {
    final int THRESHOLD = 3000;

    Timing timing = new Timing();
    Reaper reaper = null;//w ww .  j av a 2s .  c om
    Future<Void> watcher = null;
    CuratorFramework client = makeClient(timing, null);
    try {
        client.start();
        client.create().creatingParentsIfNeeded().forPath("/one/two/three");

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));

        final Queue<Reaper.PathHolder> holders = new ConcurrentLinkedQueue<Reaper.PathHolder>();
        final ExecutorService pool = Executors.newCachedThreadPool();
        ScheduledExecutorService service = new ScheduledThreadPoolExecutor(1) {
            @Override
            public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
                final Reaper.PathHolder pathHolder = (Reaper.PathHolder) command;
                holders.add(pathHolder);
                final ScheduledFuture<?> f = super.schedule(command, delay, unit);
                pool.submit(new Callable<Void>() {
                    @Override
                    public Void call() throws Exception {
                        f.get();
                        holders.remove(pathHolder);
                        return null;
                    }
                });
                return f;
            }
        };

        reaper = new Reaper(client, service, THRESHOLD);
        reaper.start();
        reaper.addPath("/one/two/three");

        long start = System.currentTimeMillis();
        boolean emptyCountIsCorrect = false;
        while (((System.currentTimeMillis() - start) < timing.forWaiting().milliseconds())
                && !emptyCountIsCorrect) // need to loop as the Holder can go in/out of the Reaper's DelayQueue
        {
            for (Reaper.PathHolder holder : holders) {
                if (holder.path.endsWith("/one/two/three")) {
                    emptyCountIsCorrect = (holder.emptyCount > 0);
                    break;
                }
            }
            Thread.sleep(1);
        }
        Assert.assertTrue(emptyCountIsCorrect);

        client.create().forPath("/one/two/three/foo");

        Thread.sleep(2 * (THRESHOLD / Reaper.EMPTY_COUNT_THRESHOLD));
        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));
        client.delete().forPath("/one/two/three/foo");

        Thread.sleep(THRESHOLD);
        timing.sleepABit();

        Assert.assertNull(client.checkExists().forPath("/one/two/three"));
    } finally {
        if (watcher != null) {
            watcher.cancel(true);
        }
        IOUtils.closeQuietly(reaper);
        IOUtils.closeQuietly(client);
    }
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.TestMultithreadedTableProvider.java

@Test
public void removeTableNotPartitioned() throws InterruptedException, StageException {
    String schema = "db";
    String table1Name = "table1";
    String table2Name = "table2";
    String offsetCol = null;//from w w w . ja  v  a 2 s . c om
    final String partitionSize = null;
    int maxActivePartitions = 0;
    int threadNumber = 0;
    int numThreads = 1;

    TableContext table1 = createTableContext(schema, table1Name, offsetCol, partitionSize, maxActivePartitions,
            true);
    TableContext table2 = createTableContext(schema, table2Name, offsetCol, partitionSize, maxActivePartitions,
            true);
    Map<String, TableContext> tableContextMap = new HashMap<>();

    tableContextMap.put(table1.getQualifiedName(), table1);
    tableContextMap.put(table2.getQualifiedName(), table2);
    Queue<String> sortedTableOrder = new LinkedList<>();
    sortedTableOrder.add(table1.getQualifiedName());
    sortedTableOrder.add(table2.getQualifiedName());

    Map threadNumToMaxTableSlots = new HashMap<>();

    BatchTableStrategy batchTableStrategy = BatchTableStrategy.PROCESS_ALL_AVAILABLE_ROWS_FROM_TABLE;
    MultithreadedTableProvider provider = new MultithreadedTableProvider(tableContextMap, sortedTableOrder,
            threadNumToMaxTableSlots, numThreads, batchTableStrategy);

    TableRuntimeContext tableRuntimeContext = provider.nextTable(threadNumber);
    Assert.equals(table1Name, tableRuntimeContext.getSourceTableContext().getTableName());
    provider.releaseOwnedTable(tableRuntimeContext, threadNumber);

    tableRuntimeContext = provider.nextTable(threadNumber);
    Assert.equals(table2Name, tableRuntimeContext.getSourceTableContext().getTableName());
    provider.releaseOwnedTable(tableRuntimeContext, threadNumber);

    tableContextMap.remove(table2.getQualifiedName());
    sortedTableOrder.remove(table2.getQualifiedName());
    //Set removed table lists
    provider.setTableContextMap(tableContextMap, sortedTableOrder);

    tableRuntimeContext = provider.nextTable(threadNumber);

    Assert.equals(table1Name, tableRuntimeContext.getSourceTableContext().getTableName());
    provider.releaseOwnedTable(tableRuntimeContext, threadNumber);

    tableRuntimeContext = provider.nextTable(threadNumber);
    Assert.equals(table1Name, tableRuntimeContext.getSourceTableContext().getTableName());
    provider.releaseOwnedTable(tableRuntimeContext, threadNumber);
}