org.atmosphere.cache.AbstractBroadcasterCache Maven / Gradle / Ivy
/*
* Copyright 2017 Async-IO.org
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.atmosphere.cache;
import org.atmosphere.cpr.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.BroadcasterCache;
import org.atmosphere.cpr.BroadcasterCacheListener;
import org.atmosphere.util.ExecutorsFactory;
import com.vaadin.external.org.slf4j.Logger;
import com.vaadin.external.org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* Abstract {@link org.atmosphere.cpr.BroadcasterCache} which is used to implement headers, query parameters or
* session based caching.
*
* @author Paul Khodchenkov
* @author Jeanfrancois Arcand
*/
public abstract class AbstractBroadcasterCache implements BroadcasterCache {
private final Logger logger = LoggerFactory.getLogger(AbstractBroadcasterCache.class);
protected final List messages = new LinkedList();
protected final Set messagesIds = new HashSet();
protected final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
protected ScheduledFuture scheduledFuture;
protected long maxCacheTime = TimeUnit.MINUTES.toMillis(2); // 2 minutes
protected long invalidateCacheInterval = TimeUnit.MINUTES.toMillis(1); // 1 minute
protected ScheduledExecutorService reaper = Executors.newSingleThreadScheduledExecutor();
protected boolean isShared;
protected final List inspectors = new LinkedList();
protected final List