Package org.wso2.carbon.clustering.hazelcast.jsr107

Examples of org.wso2.carbon.clustering.hazelcast.jsr107.Util


public class RandomEvictionAlgorithm implements EvictionAlgorithm {
    private static Random random = new Random();

    @SuppressWarnings("unchecked")
    public void evict(CacheImpl cache) {
        CacheEntry lruCacheEntry = null;
        Collection all = cache.getAll();
        int evictionIndex = random.nextInt(all.size());
        int index = 0;

        for (Object anAll : all) {
            CacheEntry cacheEntry = (CacheEntry) anAll;
            if (index == evictionIndex) {
                lruCacheEntry = cacheEntry;
                break;
            }
            index++;
View Full Code Here


*/
public class EvictionUtil {

    public static void evict(CacheImpl cache, EvictionAlgorithm algorithm) {

        HazelcastCacheManager cacheManager = (HazelcastCacheManager) cache.getCacheManager();
        int ownerTenantId = cacheManager.getOwnerTenantId();
        String cacheManagerName = cacheManager.getName();
        String cacheName = cache.getName();
        synchronized ((ownerTenantId + "." + cacheManagerName + "." + cacheName).intern()) {
            algorithm.evict(cache);
        }
    }
View Full Code Here

        CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("testLRUCacheEviction-manager");
        String cacheName = "testLRUCacheEviction";
        Cache<String, Integer> cache = cacheManager.getCache(cacheName);

        ((CacheImpl) cache).setCapacity(2);
        ((CacheImpl) cache).setEvictionAlgorithm(new LeastRecentlyUsedEvictionAlgorithm());

        String key1 = "key1";
        String key2 = "key2";
        String key3 = "key3";
        int value1 = 9876;
View Full Code Here

        CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("testMRUCacheEviction-manager");
        String cacheName = "testMRUCacheEviction";
        Cache<String, Integer> cache = cacheManager.getCache(cacheName);

        ((CacheImpl) cache).setCapacity(2);
        ((CacheImpl) cache).setEvictionAlgorithm(new MostRecentlyUsedEvictionAlgorithm());

        String key1 = "key1";
        String key2 = "key2";
        String key3 = "key3";
        int value1 = 9876;
View Full Code Here

          description = "")
    public void testDefaultMRUCacheEviction() {
        CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("testDefaultMRUCacheEviction-manager");
        String cacheName = "testDefaultMRUCacheEviction";
        Cache<String, Integer> cache = cacheManager.getCache(cacheName);
        ((CacheImpl) cache).setEvictionAlgorithm(new MostRecentlyUsedEvictionAlgorithm());
        for (int i = 0; i < 10000; i++) {
            cache.put("key" + i, i);
        }
        assertEquals(((CacheImpl) cache).getAll().size(), CachingConstants.DEFAULT_CACHE_CAPACITY);
    }
View Full Code Here

        CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("testRandomCacheEviction-manager");
        String cacheName = "testRandomCacheEviction";
        Cache<String, Integer> cache = cacheManager.getCache(cacheName);

        ((CacheImpl) cache).setCapacity(2);
        ((CacheImpl) cache).setEvictionAlgorithm(new RandomEvictionAlgorithm());

        String key1 = "key1";
        String key2 = "key2";
        String key3 = "key3";
        int value1 = 9876;
View Full Code Here

          description = "")
    public void testDefaultRandomCacheEviction() {
        CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("testDefaultRandomCacheEviction-manager");
        String cacheName = "testDefaultRandomCacheEviction";
        Cache<String, Integer> cache = cacheManager.getCache(cacheName);
        ((CacheImpl) cache).setEvictionAlgorithm(new RandomEvictionAlgorithm());
        for (int i = 0; i < 10000; i++) {
            cache.put("key" + i, i);
        }
        assertEquals(((CacheImpl) cache).getAll().size(), CachingConstants.DEFAULT_CACHE_CAPACITY);
    }
View Full Code Here

        }

        public void run() {
            try {
                MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
                Event<MessageContext> event = new Event(msgCtx);
                subscriptions = subscriptionManager.getMatchingSubscriptions(event);
            } catch (EventException e) {
                handleException("Matching subscriptions fetching error", e);
            }
View Full Code Here

     * @throws EventException event
     */
    private void processGetStatusRequest(MessageContext mc,
                                         ResponseMessageBuilder messageBuilder)
            throws AxisFault, EventException {
        Subscription subscription =
                SubscriptionMessageBuilder.createGetStatusMessage(mc);
        if (log.isDebugEnabled()) {
            log.debug("GetStatus request recived for SynapseSubscription ID : " +
                    subscription.getId());
        }
        subscription = subscriptionManager.getSubscription(subscription.getId());
        if (subscription != null) {
            if (log.isDebugEnabled()) {
                log.debug("Sending GetStatus responce for SynapseSubscription ID : " +
                        subscription.getId());
            }
            //send the responce
            SOAPEnvelope soapEnvelope = messageBuilder.genGetStatusResponse(subscription);
            dispatchResponse(soapEnvelope, EventingConstants.WSE_GET_STATUS_RESPONSE,
                    mc, false);
View Full Code Here


    public SynapseSubscription() {
        this.setId(UIDGenerator.generateURNString());
        this.setDeliveryMode(EventingConstants.WSE_DEFAULT_DELIVERY_MODE);
        SubscriptionData subscriptionData = new SubscriptionData();
        subscriptionData.setProperty(SynapseEventingConstants.STATIC_ENTRY, "false");
        this.setSubscriptionData(subscriptionData);
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.clustering.hazelcast.jsr107.Util

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.