Java 类com.hazelcast.core.Instance 实例源码

项目:hazelcast-archive    文件:TransactionImpl.java   
public Data attachPutOp(String name, Object key, Data value, long timeout, long ttl, boolean newRecord) {
    Instance.InstanceType instanceType = ConcurrentMapManager.getInstanceType(name);
    Object matchValue = (instanceType.isMultiMap()) ? toObject(value) : null;
    TransactionRecord rec = findTransactionRecord(name, key, matchValue);
    if (rec == null) {
        rec = new TransactionRecord(name, key, value, newRecord);
        rec.timeout = timeout;
        rec.ttl = ttl;
        transactionRecords.add(rec);
        return null;
    } else {
        Data old = rec.value;
        rec.value = value;
        rec.removed = false;
        return old;
    }
}
项目:hazelcast-archive    文件:TransactionImpl.java   
public Data attachRemoveOp(String name, Object key, Data value, boolean newRecord, int valueCount) {
    Instance.InstanceType instanceType = ConcurrentMapManager.getInstanceType(name);
    Object matchValue = (instanceType.isMultiMap()) ? toObject(value) : null;
    TransactionRecord rec = findTransactionRecord(name, key, matchValue);
    Data oldValue = null;
    if (rec == null) {
        rec = new TransactionRecord(name, key, value, newRecord);
        transactionRecords.add(rec);
    } else {
        oldValue = rec.value;
        rec.value = value;
    }
    rec.valueCount = valueCount;
    rec.removed = true;
    return oldValue;
}
项目:hazelcast-archive    文件:InstanceListenerManager.java   
public void notifyListeners(Packet packet) {
    String id = (String) toObject(packet.getKey());
    int i = (Integer) toObject(packet.getValue());
    InstanceEvent.InstanceEventType instanceEventType = (i == 0) ? InstanceEvent.InstanceEventType.CREATED : InstanceEvent.InstanceEventType.DESTROYED;
    InstanceEvent event = new InstanceEvent(instanceEventType, (Instance) client.getClientProxy(id));
    for (final InstanceListener listener : instanceListeners) {
        switch (instanceEventType) {
            case CREATED:
                listener.instanceCreated(event);
                break;
            case DESTROYED:
                listener.instanceDestroyed(event);
                break;
            default:
                break;
        }
    }
}
项目:usergrid    文件:HazelcastTest.java   
@Test
public void doTest() {
    logger.info( "do test" );
    Hazelcast.addInstanceListener( this );

    ITopic<Object> topic = Hazelcast.getTopic( "default" );
    topic.addMessageListener( this );
    topic.publish( "my-message-object" );

    Collection<Instance> instances = Hazelcast.getInstances();
    for ( Instance instance : instances ) {
        logger.info( "ID: [" + instance.getId() + "] Type: [" + instance.getInstanceType() + "]" );
    }

    Set<Member> setMembers = Hazelcast.getCluster().getMembers();
    for ( Member member : setMembers ) {
        logger.info( "isLocalMember " + member.localMember() );
        logger.info( "member.inetsocketaddress " + member.getInetSocketAddress() );
    }
}
项目:health-and-care-developer-network    文件:TransactionImpl.java   
public Data attachPutOp(String name, Object key, Data value, long timeout, long ttl, boolean newRecord, int index) {
    Instance.InstanceType instanceType = ConcurrentMapManager.getInstanceType(name);
    Object matchValue = (instanceType.isMultiMap()) ? toObject(value) : null;
    TransactionRecord rec = findTransactionRecord(name, key, matchValue);
    if (rec == null) {
        rec = new TransactionRecord(name, key, value, newRecord);
        rec.timeout = timeout;
        rec.ttl = ttl;
        rec.index = index;
        transactionRecords.add(rec);
        return null;
    } else {
        Data old = rec.value;
        rec.value = value;
        rec.removed = false;
        rec.index = index;
        return old;
    }
}
项目:health-and-care-developer-network    文件:TransactionImpl.java   
public Data attachRemoveOp(String name, Object key, Data value, boolean newRecord, int valueCount) {
    Instance.InstanceType instanceType = ConcurrentMapManager.getInstanceType(name);
    Object matchValue = (instanceType.isMultiMap()) ? toObject(value) : null;
    TransactionRecord rec = findTransactionRecord(name, key, matchValue);
    Data oldValue = null;
    if (rec == null) {
        rec = new TransactionRecord(name, key, value, newRecord);
        transactionRecords.add(rec);
    } else {
        oldValue = rec.value;
        rec.value = value;
    }
    rec.valueCount = valueCount;
    rec.removed = true;
    return oldValue;
}
项目:health-and-care-developer-network    文件:InstanceListenerManager.java   
public void notifyListeners(Packet packet) {
    String id = (String) toObject(packet.getKey());
    int i = (Integer) toObject(packet.getValue());
    InstanceEvent.InstanceEventType instanceEventType = (i == 0) ? InstanceEvent.InstanceEventType.CREATED
                                                                 : InstanceEvent.InstanceEventType.DESTROYED;
    InstanceEvent event = new InstanceEvent(instanceEventType, (Instance) client.getClientProxy(id));
    for (final InstanceListener listener : instanceListeners) {
        switch (instanceEventType) {
            case CREATED:
                listener.instanceCreated(event);
                break;
            case DESTROYED:
                listener.instanceDestroyed(event);
                break;
            default:
                break;
        }
    }
}
项目:hazelcast-archive    文件:Entries.java   
public Entries(ConcurrentMapManager concurrentMapManager, String name, ClusterOperation operation, Predicate predicate) {
    this.concurrentMapManager = concurrentMapManager;
    this.name = name;
    this.operation = operation;
    this.predicate = predicate;
    if (name.startsWith(Prefix.MULTIMAP)) {
        colKeyValues = new LinkedList<Map.Entry>();
    } else {
        colKeyValues = new HashSet<Map.Entry>();
    }
    TransactionImpl txn = ThreadContext.get().getCallContext().getTransaction();
    this.checkValue = (Instance.InstanceType.MAP == BaseManager.getInstanceType(name)) &&
            (operation == CONCURRENT_MAP_ITERATE_VALUES
                    || operation == CONCURRENT_MAP_ITERATE_ENTRIES);
    if (txn != null) {
        List<Map.Entry> entriesUnderTxn = txn.newEntries(name);
        if (entriesUnderTxn != null) {
            if (predicate != null) {
                for (Map.Entry entry : entriesUnderTxn) {
                    if (predicate.apply((MapEntry) entry)) {
                        colKeyValues.add(entry);
                    }
                }
            } else {
                colKeyValues.addAll(entriesUnderTxn);
            }
        }
    }
}
项目:hazelcast-archive    文件:Entries.java   
public void remove() {
    if (BaseManager.getInstanceType(name) == Instance.InstanceType.MULTIMAP) {
        if (operation == CONCURRENT_MAP_ITERATE_KEYS) {
            ((MultiMap) concurrentMapManager.node.factory.getOrCreateProxyByName(name)).remove(entry.getKey(), null);
        } else {
            ((MultiMap) concurrentMapManager.node.factory.getOrCreateProxyByName(name)).remove(entry.getKey(), entry.getValue());
        }
    } else {
        ((IRemoveAwareProxy) concurrentMapManager.node.factory.getOrCreateProxyByName(name)).removeKey(entry.getKey());
    }
    it.remove();
}
项目:hazelcast-archive    文件:LockInformationCallable.java   
public Map<String, MapLockState> call() throws Exception {
    final String globalLockMapName = Prefix.HAZELCAST + "Locks";
    final List<String> mapNames = new ArrayList<String>();
    mapNames.add(globalLockMapName);
    for (Instance instance : hazelcastInstance.getInstances()) {
        if (instance.getInstanceType().isMap()) {
            IMap imap = (IMap) instance;
            mapNames.add(imap.getName());
        }
    }
    final ConcurrentHashMap<String, MapLockState> lockInformation = new ConcurrentHashMap<String, MapLockState>();
    getClusterService().enqueueAndWait(new Processable() {
        public void process() {
            for (String mapName : mapNames) {
                final CMap cmap = getCMap(mapName);
                Map<Object, DistributedLock> lockOwners = new HashMap<Object, DistributedLock>();
                Map<Object, DistributedLock> lockRequested = new HashMap<Object, DistributedLock>();
                cmap.collectScheduledLocks(lockOwners, lockRequested);
                MapLockState mapLockState = new MapLockState();
                mapLockState.setLockOwners(lockOwners);
                mapLockState.setLockRequested(lockRequested);
                mapLockState.setGlobalLock(mapName.equals(globalLockMapName));
                mapLockState.setMapName(mapName);
                lockInformation.put(mapName, mapLockState);
            }
        }
    }, 5);
    return lockInformation;
}
项目:hazelcast-archive    文件:ListenerManager.java   
protected void customRun() throws InterruptedException {
    try {
        Object obj = queue.poll(100, TimeUnit.MILLISECONDS);
        if (obj == null) {
            return;
        }
        if (obj instanceof Packet) {
            Packet packet = (Packet) obj;
            if (packet.getName() == null) {
                Object eventType = toObject(packet.getValue());
                if (new Integer(0).equals(eventType) || new Integer(2).equals(eventType)) {
                    instanceListenerManager.notifyListeners(packet);
                } else {
                    membershipListenerManager.notifyListeners(packet);
                }
            } else if (getInstanceType(packet.getName()).equals(Instance.InstanceType.TOPIC)) {
                messageListenerManager.notifyMessageListeners(packet);
            } else if (getInstanceType(packet.getName()).equals(Instance.InstanceType.QUEUE)) {
                queueItemListenerManager.notifyListeners(packet);
            } else {
                entryListenerManager.notifyListeners(packet);
            }
        } else if (obj instanceof Runnable) {
            ((Runnable) obj).run();
        }
    } catch (InterruptedException ine) {
        throw ine;
    } catch (Throwable ignored) {
        ignored.printStackTrace();
    }
}
项目:health-and-care-developer-network    文件:HazelcastCacheManager.java   
public void afterPropertiesSet() throws Exception {
    final Collection<Instance> instances = hazelcastInstance.getInstances();
    for (Instance instance : instances) {
        if (instance.getInstanceType() == InstanceType.MAP) {
            final IMap<Object, Object> map = (IMap) instance;
            caches.put(map.getName(), new HazelcastCache(map));
        }
    }
}
项目:health-and-care-developer-network    文件:Entries.java   
public Entries(ConcurrentMapManager concurrentMapManager, String name, ClusterOperation operation, Predicate predicate) {
    this.concurrentMapManager = concurrentMapManager;
    this.name = name;
    this.operation = operation;
    if (name.startsWith(Prefix.MULTIMAP)) {
        colKeyValues = new LinkedList<Map.Entry>();
    } else {
        colKeyValues = new HashSet<Map.Entry>();
    }
    TransactionImpl txn = ThreadContext.get().getCallContext().getTransaction();
    this.checkValue = (Instance.InstanceType.MAP == BaseManager.getInstanceType(name)) &&
            (operation == CONCURRENT_MAP_ITERATE_VALUES
                    || operation == CONCURRENT_MAP_ITERATE_ENTRIES);
    if (txn != null) {
        List<Map.Entry> entriesUnderTxn = txn.newEntries(name);
        if (entriesUnderTxn != null) {
            if (predicate != null) {
                for (Map.Entry entry : entriesUnderTxn) {
                    if (predicate.apply((MapEntry) entry)) {
                        colKeyValues.add(entry);
                    }
                }
            } else {
                colKeyValues.addAll(entriesUnderTxn);
            }
        }
    }
}
项目:health-and-care-developer-network    文件:Entries.java   
public void remove() {
    if (BaseManager.getInstanceType(name) == Instance.InstanceType.MULTIMAP) {
        if (operation == CONCURRENT_MAP_ITERATE_KEYS) {
            ((MultiMap) concurrentMapManager.node.factory.getOrCreateProxyByName(name)).remove(entry.getKey(), null);
        } else {
            ((MultiMap) concurrentMapManager.node.factory.getOrCreateProxyByName(name)).remove(entry.getKey(), entry.getValue());
        }
    } else {
        ((IRemoveAwareProxy) concurrentMapManager.node.factory.getOrCreateProxyByName(name)).removeKey(entry.getKey());
    }
    it.remove();
}
项目:health-and-care-developer-network    文件:TransactionImpl.java   
public void commit() {
    if (instanceType == Instance.InstanceType.QUEUE) {
        commitQueue();
    } else {
        commitMap();
    }
}
项目:health-and-care-developer-network    文件:TransactionImpl.java   
public void rollback() {
    if (instanceType == Instance.InstanceType.QUEUE) {
        rollbackQueue();
    } else {
        rollbackMap();
    }
}
项目:health-and-care-developer-network    文件:LockInformationCallable.java   
public Map<String, MapLockState> call() throws Exception {
    final String globalLockMapName = Prefix.HAZELCAST + "Locks";
    final List<String> mapNames = new ArrayList<String>();
    mapNames.add(globalLockMapName);
    for (Instance instance : hazelcastInstance.getInstances()) {
        if (instance.getInstanceType().isMap()) {
            IMap imap = (IMap) instance;
            mapNames.add(imap.getName());
        }
    }
    final ConcurrentHashMap<String, MapLockState> lockInformation = new ConcurrentHashMap<String, MapLockState>();
    getClusterService().enqueueAndWait(new Processable() {
        public void process() {
            for (String mapName : mapNames) {
                final CMap cmap = getCMap(mapName);
                Map<Object, DistributedLock> lockOwners = new HashMap<Object, DistributedLock>();
                Map<Object, DistributedLock> lockRequested = new HashMap<Object, DistributedLock>();
                cmap.collectScheduledLocks(lockOwners, lockRequested);
                MapLockState mapLockState = new MapLockState();
                mapLockState.setLockOwners(lockOwners);
                mapLockState.setLockRequested(lockRequested);
                mapLockState.setGlobalLock(mapName.equals(globalLockMapName));
                mapLockState.setMapName(mapName);
                lockInformation.put(mapName, mapLockState);
            }
        }
    }, 5);
    return lockInformation;
}
项目:health-and-care-developer-network    文件:ListenerManager.java   
protected void customRun() throws InterruptedException {
    try {
        Object obj = queue.poll(100, TimeUnit.MILLISECONDS);
        if (obj == null) {
            return;
        }
        if (obj instanceof Packet) {
            Packet packet = (Packet) obj;
            if (packet.getName() == null) {
                Object eventType = toObject(packet.getValue());
                if (new Integer(0).equals(eventType) || new Integer(2).equals(eventType)) {
                    instanceListenerManager.notifyListeners(packet);
                } else {
                    membershipListenerManager.notifyListeners(packet);
                }
            } else if (getInstanceType(packet.getName()).equals(Instance.InstanceType.TOPIC)) {
                messageListenerManager.notifyMessageListeners(packet);
            } else if (getInstanceType(packet.getName()).equals(Instance.InstanceType.QUEUE)) {
                queueItemListenerManager.notifyListeners(packet);
            } else {
                entryListenerManager.notifyListeners(packet);
            }
        } else if (obj instanceof Runnable) {
            ((Runnable) obj).run();
        }
    } catch (InterruptedException ine) {
        throw ine;
    } catch (Throwable ignored) {
        ignored.printStackTrace();
    }
}
项目:hazelcast-archive    文件:TransactionImpl.java   
public void commit() {
    if (instanceType == Instance.InstanceType.QUEUE)
        commitQueue();
    else
        commitMap();
}
项目:hazelcast-archive    文件:TransactionImpl.java   
public void rollback() {
    if (instanceType == Instance.InstanceType.QUEUE)
        rollbackQueue();
    else
        rollbackMap();
}
项目:hazelcast-archive    文件:ListProxyImpl.java   
public Instance.InstanceType getInstanceType() {
    return Instance.InstanceType.LIST;
}
项目:hazelcast-archive    文件:MultiMapEntryIterator.java   
public MultiMapEntryIterator(Iterator it, EntryHolder proxy, Instance.InstanceType instanceType) {
    super(it, proxy, instanceType);
}
项目:hazelcast-archive    文件:LightMultiMapEntrySet.java   
public LightMultiMapEntrySet(Set<K> set, MultiMapClientProxy proxy, Instance.InstanceType instanceType) {
    this.keySet = set;
    this.proxy = proxy;
    this.instanceType = instanceType;
}
项目:hazelcast-archive    文件:LightEntrySetSet.java   
public LightEntrySetSet(Collection collection, MapClientProxy<K, V> proxy, Instance.InstanceType instanceType) {
    this.entrySet = collection;
    this.proxy = proxy;
    this.instanceType = instanceType;
}
项目:hazelcast-archive    文件:MapEntrySetIterator.java   
public MapEntrySetIterator(Iterator iterator, EntryHolder<K, V> proxy, Instance.InstanceType instanceType) {
    this.it = iterator;
    this.proxy = proxy;
    this.instanceType = instanceType;
}
项目:hazelcast-archive    文件:MapEntrySetIterator.java   
public V setValue(V arg0) {
    if (instanceType.equals(Instance.InstanceType.MULTIMAP)) {
        throw new UnsupportedOperationException();
    }
    return (V) ((IMap) proxy).put(key, arg0);
}
项目:hazelcast-archive    文件:LightEntrySet.java   
public LightEntrySet(Set<K> set, MapClientProxy<K, V> proxy, Instance.InstanceType instanceType) {
    this.keySet = set;
    this.proxy = proxy;
    this.instanceType = instanceType;
}
项目:hazelcast-archive    文件:MapEntryIterator.java   
public MapEntryIterator(Iterator<K> it, EntryHolder<K, V> proxy, Instance.InstanceType instanceType) {
    this.it = it;
    this.proxy = proxy;
    this.instanceType = instanceType;
}
项目:hazelcast-archive    文件:MapEntryIterator.java   
public V setValue(V arg0) {
    if (instanceType.equals(Instance.InstanceType.MULTIMAP)) {
        throw new UnsupportedOperationException();
    }
    return (V) ((IMap) proxy).put(key, arg0);
}
项目:hazelcast-archive    文件:SemaphoreClientProxy.java   
public InstanceType getInstanceType() {
    return Instance.InstanceType.SEMAPHORE;
}
项目:usergrid    文件:HazelcastLifecycleMonitor.java   
@Override
public void instanceCreated( InstanceEvent event ) {
    Instance instance = event.getInstance();
    logger.info( "Created instance ID: [{}] Type: [{}]", instance.getId(), instance.getInstanceType() );
}
项目:usergrid    文件:HazelcastLifecycleMonitor.java   
@Override
public void instanceDestroyed( InstanceEvent event ) {
    Instance instance = event.getInstance();
    logger.info( "Destroyed instance ID: [{}] Type: [{}]", instance.getId(), instance.getInstanceType() );
}
项目:usergrid    文件:HazelcastTest.java   
@Override
public void instanceCreated( InstanceEvent event ) {
    Instance instance = event.getInstance();
    logger.info( "Created instance ID: [" + instance.getId() + "] Type: [" + instance.getInstanceType() + "]" );
}
项目:usergrid    文件:HazelcastTest.java   
@Override
public void instanceDestroyed( InstanceEvent event ) {
    Instance instance = event.getInstance();
    logger.info( "Destroyed isntance ID: [" + instance.getId() + "] Type: [" + instance.getInstanceType() + "]" );
}
项目:health-and-care-developer-network    文件:ListProxyImpl.java   
public Instance.InstanceType getInstanceType() {
    return Instance.InstanceType.LIST;
}
项目:health-and-care-developer-network    文件:MultiMapEntryIterator.java   
public MultiMapEntryIterator(Iterator it, EntryHolder proxy, Instance.InstanceType instanceType) {
    super(it, proxy, instanceType);
}
项目:health-and-care-developer-network    文件:LightMultiMapEntrySet.java   
public LightMultiMapEntrySet(Set<K> set, MultiMapClientProxy proxy, Instance.InstanceType instanceType) {
    this.keySet = set;
    this.proxy = proxy;
    this.instanceType = instanceType;
}
项目:health-and-care-developer-network    文件:LightEntrySetSet.java   
public LightEntrySetSet(Collection collection, MapClientProxy<K, V> proxy, Instance.InstanceType instanceType) {
    this.entrySet = collection;
    this.proxy = proxy;
    this.instanceType = instanceType;
}
项目:health-and-care-developer-network    文件:MapEntrySetIterator.java   
public MapEntrySetIterator(Iterator iterator, EntryHolder<K, V> proxy, Instance.InstanceType instanceType) {
    this.it = iterator;
    this.proxy = proxy;
    this.instanceType = instanceType;
}
项目:health-and-care-developer-network    文件:MapEntrySetIterator.java   
public V setValue(V arg0) {
    if (instanceType.equals(Instance.InstanceType.MULTIMAP)) {
        throw new UnsupportedOperationException();
    }
    return (V) ((IMap) proxy).put(key, arg0);
}