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; } }
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; }
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; } } }
@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() ); } }
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; } }
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); } } } }
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(); }
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; }
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(); } }
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)); } } }
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); } } } }
public void commit() { if (instanceType == Instance.InstanceType.QUEUE) { commitQueue(); } else { commitMap(); } }
public void rollback() { if (instanceType == Instance.InstanceType.QUEUE) { rollbackQueue(); } else { rollbackMap(); } }
public void commit() { if (instanceType == Instance.InstanceType.QUEUE) commitQueue(); else commitMap(); }
public void rollback() { if (instanceType == Instance.InstanceType.QUEUE) rollbackQueue(); else rollbackMap(); }
public Instance.InstanceType getInstanceType() { return Instance.InstanceType.LIST; }
public MultiMapEntryIterator(Iterator it, EntryHolder proxy, Instance.InstanceType instanceType) { super(it, proxy, instanceType); }
public LightMultiMapEntrySet(Set<K> set, MultiMapClientProxy proxy, Instance.InstanceType instanceType) { this.keySet = set; this.proxy = proxy; this.instanceType = instanceType; }
public LightEntrySetSet(Collection collection, MapClientProxy<K, V> proxy, Instance.InstanceType instanceType) { this.entrySet = collection; this.proxy = proxy; this.instanceType = instanceType; }
public MapEntrySetIterator(Iterator iterator, EntryHolder<K, V> proxy, Instance.InstanceType instanceType) { this.it = iterator; this.proxy = proxy; this.instanceType = instanceType; }
public V setValue(V arg0) { if (instanceType.equals(Instance.InstanceType.MULTIMAP)) { throw new UnsupportedOperationException(); } return (V) ((IMap) proxy).put(key, arg0); }
public LightEntrySet(Set<K> set, MapClientProxy<K, V> proxy, Instance.InstanceType instanceType) { this.keySet = set; this.proxy = proxy; this.instanceType = instanceType; }
public MapEntryIterator(Iterator<K> it, EntryHolder<K, V> proxy, Instance.InstanceType instanceType) { this.it = it; this.proxy = proxy; this.instanceType = instanceType; }
public InstanceType getInstanceType() { return Instance.InstanceType.SEMAPHORE; }
@Override public void instanceCreated( InstanceEvent event ) { Instance instance = event.getInstance(); logger.info( "Created instance ID: [{}] Type: [{}]", instance.getId(), instance.getInstanceType() ); }
@Override public void instanceDestroyed( InstanceEvent event ) { Instance instance = event.getInstance(); logger.info( "Destroyed instance ID: [{}] Type: [{}]", instance.getId(), instance.getInstanceType() ); }
@Override public void instanceCreated( InstanceEvent event ) { Instance instance = event.getInstance(); logger.info( "Created instance ID: [" + instance.getId() + "] Type: [" + instance.getInstanceType() + "]" ); }
@Override public void instanceDestroyed( InstanceEvent event ) { Instance instance = event.getInstance(); logger.info( "Destroyed isntance ID: [" + instance.getId() + "] Type: [" + instance.getInstanceType() + "]" ); }