Java Code Examples for java.util.concurrent.CopyOnWriteArraySet#remove()

The following examples show how to use java.util.concurrent.CopyOnWriteArraySet#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicServerJob.java    From Alice-LiveMan with GNU Affero General Public License v3.0 6 votes vote down vote up
@Scheduled(cron = "0/5 * * * * ?")
public void destroyServerJob() {
    CopyOnWriteArraySet<ServerInfo> servers = liveManSetting.getServers();
    for (ServerInfo server : servers) {
        if (server.getExternalServiceType() != null) {
            if (server.getDateCreated() == null) {
                server.setDateCreated(System.currentTimeMillis());
            }
            // 在1分钟内就要进入下一个收费周期了,检查是否需要释放服务器
            if (((System.currentTimeMillis() - server.getDateCreated()) / 1000.0 / 60) % 60 > 59) {
                VideoInfo currentVideo = server.getCurrentVideo();
                if (currentVideo == null) {
                    servers.remove(server);
                    dynamicServerService.destroy(server);
                } else {
                    log.info("服务器[" + server.getRemark() + "]正在被节目[videoId=" + currentVideo.getVideoUnionId() + "]使用,续期。");
                }
            }
        }
    }
    settingConfig.saveSetting(liveManSetting);
}
 
Example 2
Source File: DefaultEventBus.java    From sofa-registry with Apache License 2.0 5 votes vote down vote up
/**
 * @see EventBus#unRegister(Class, EventSubscriber)
 */
@Override
public void unRegister(Class<? extends Event> eventClass, EventSubscriber eventSubscriber) {
    CopyOnWriteArraySet<EventSubscriber> set = eventSubscriberMap.get(eventClass);
    if (set != null) {
        set.remove(eventSubscriber);
        LOGGER.debug("UnRegister subscriber: {} of event: {}.", eventSubscriber, eventClass);
    }
}
 
Example 3
Source File: EventAdminServiceImpl.java    From sofa-ark with Apache License 2.0 5 votes vote down vote up
@Override
public void unRegister(EventHandler eventHandler) {
    CopyOnWriteArraySet<EventHandler> set = SUBSCRIBER_MAP.get(eventHandler.getClass()
        .getClassLoader());
    if (set != null) {
        set.remove(eventHandler);
        LOGGER.debug(String.format("Unregister event handler: %s.", eventHandler));
    }
}
 
Example 4
Source File: EventBus.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * 反注册一个订阅者
 *
 * @param eventClass 事件类型
 * @param subscriber 订阅者
 */
public static void unRegister(Class<? extends Event> eventClass, Subscriber subscriber) {
    CopyOnWriteArraySet<Subscriber> set = SUBSCRIBER_MAP.get(eventClass);
    if (set != null) {
        set.remove(subscriber);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("UnRegister subscriber: {} of event: {}.", subscriber, eventClass);
        }
    }
}
 
Example 5
Source File: CopyOnWriteArraySetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sets with equal elements are equal
 */
public void testEquals() {
    CopyOnWriteArraySet a = populatedSet(3);
    CopyOnWriteArraySet b = populatedSet(3);
    assertTrue(a.equals(b));
    assertTrue(b.equals(a));
    assertTrue(a.containsAll(b));
    assertTrue(b.containsAll(a));
    assertEquals(a.hashCode(), b.hashCode());
    assertEquals(a.size(), b.size());

    a.add(m1);
    assertFalse(a.equals(b));
    assertFalse(b.equals(a));
    assertTrue(a.containsAll(b));
    assertFalse(b.containsAll(a));
    b.add(m1);
    assertTrue(a.equals(b));
    assertTrue(b.equals(a));
    assertTrue(a.containsAll(b));
    assertTrue(b.containsAll(a));
    assertEquals(a.hashCode(), b.hashCode());

    Object x = a.iterator().next();
    a.remove(x);
    assertFalse(a.equals(b));
    assertFalse(b.equals(a));
    assertFalse(a.containsAll(b));
    assertTrue(b.containsAll(a));
    a.add(x);
    assertTrue(a.equals(b));
    assertTrue(b.equals(a));
    assertTrue(a.containsAll(b));
    assertTrue(b.containsAll(a));
    assertEquals(a.hashCode(), b.hashCode());
    assertEquals(a.size(), b.size());

    CopyOnWriteArraySet empty1 = new CopyOnWriteArraySet(Arrays.asList());
    CopyOnWriteArraySet empty2 = new CopyOnWriteArraySet(Arrays.asList());
    assertTrue(empty1.equals(empty1));
    assertTrue(empty1.equals(empty2));

    assertFalse(empty1.equals(a));
    assertFalse(a.equals(empty1));

    assertFalse(a.equals(null));
}
 
Example 6
Source File: ZKClient.java    From zkclient with Apache License 2.0 4 votes vote down vote up
/**
 * 解除对子节点的监听
 * @param path
 * @param childListener
 * @param withData 
 * @return void
 */
public void unlistenChildChanges(String path, ZKListener childListener) {
    LOG.debug("Unlisten child ["+path+"--"+childListener+"] ");
    //解除对子节点的监听
    synchronized (childListenerMap) {
        final Set<ZKListener> listeners = childListenerMap.get(path);
        if (listeners != null) {
            listeners.remove(childListener);
            LOG.debug("unlistenChildChanges:Unlistener path["+path+"--"+childListener+"] ");
        }
        if(listeners == null || listeners.isEmpty()){
            childListenerMap.remove(path);
        }
    }
    //如果监听了子节点的数据变化,则要同时解除对子节点的数据变化的监听。
    if(childListener instanceof ZKChildDataListener){
         synchronized (nodeListenerMap) {
            Set<String> dataPaths = nodeListenerMap.keySet();
            //遍历所有的节点监听器,查找是path节点的子节点,并移除监听器
            for(String dataPath : dataPaths){
                //查找path的下一级节点的监听器,并删除注册的ZKChildDataListener监听器
                int index = dataPath.lastIndexOf("/");
                if(index>0){
                    String parentPath = dataPath.substring(0, index);
                    if(path.equals(parentPath)){//如果dataPath是下一级节点
                        CopyOnWriteArraySet<ZKListener> nodeListeners = nodeListenerMap.get(dataPath);
                        if(nodeListeners != null) {
                            for(ZKListener nodeListener : nodeListeners){
                                if(nodeListener instanceof ZKChildDataListener){
                                    nodeListeners.remove(nodeListener);
                                    LOG.debug(":Unlistener child data changes ["+dataPath+"--"+nodeListener+"] ");
                                }
                            }
                        }
                         if(nodeListeners == null || nodeListeners.isEmpty()){
                             nodeListenerMap.remove(dataPath);
                         }
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: HALoadBalancerServlet.java    From database with GNU General Public License v2.0 4 votes vote down vote up
private static void removeServlet(final ServletContext servletContext,
        final HALoadBalancerServlet servlet) {

    if (servletContext == null)
        throw new IllegalArgumentException();

    if (servlet == null)
        throw new IllegalArgumentException();

    synchronized (servletContext) {

        @SuppressWarnings("unchecked")
        final CopyOnWriteArraySet<HALoadBalancerServlet> servletSet = (CopyOnWriteArraySet<HALoadBalancerServlet>) servletContext
                .getAttribute(BigdataServlet.ATTRIBUTE_LBS_INSTANCES);

        if (servletSet != null) {

            servletSet.remove(servlet);

        }
        
    }
    
}
 
Example 8
Source File: CopyOnWriteArraySetTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Sets with equal elements are equal
 */
public void testEquals() {
    CopyOnWriteArraySet a = populatedSet(3);
    CopyOnWriteArraySet b = populatedSet(3);
    assertTrue(a.equals(b));
    assertTrue(b.equals(a));
    assertTrue(a.containsAll(b));
    assertTrue(b.containsAll(a));
    assertEquals(a.hashCode(), b.hashCode());
    assertEquals(a.size(), b.size());

    a.add(m1);
    assertFalse(a.equals(b));
    assertFalse(b.equals(a));
    assertTrue(a.containsAll(b));
    assertFalse(b.containsAll(a));
    b.add(m1);
    assertTrue(a.equals(b));
    assertTrue(b.equals(a));
    assertTrue(a.containsAll(b));
    assertTrue(b.containsAll(a));
    assertEquals(a.hashCode(), b.hashCode());

    Object x = a.iterator().next();
    a.remove(x);
    assertFalse(a.equals(b));
    assertFalse(b.equals(a));
    assertFalse(a.containsAll(b));
    assertTrue(b.containsAll(a));
    a.add(x);
    assertTrue(a.equals(b));
    assertTrue(b.equals(a));
    assertTrue(a.containsAll(b));
    assertTrue(b.containsAll(a));
    assertEquals(a.hashCode(), b.hashCode());
    assertEquals(a.size(), b.size());

    CopyOnWriteArraySet empty1 = new CopyOnWriteArraySet(Arrays.asList());
    CopyOnWriteArraySet empty2 = new CopyOnWriteArraySet(Arrays.asList());
    assertTrue(empty1.equals(empty1));
    assertTrue(empty1.equals(empty2));

    assertFalse(empty1.equals(a));
    assertFalse(a.equals(empty1));

    assertFalse(a.equals(null));
}