Last active
January 4, 2016 15:59
-
-
Save cazacugmihai/8644049 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GrabResolver(name='hazelcast', root='https://oss.sonatype.org/content/repositories/snapshots', m2Compatible=true) | |
@Grab('com.hazelcast:hazelcast:3.2-SNAPSHOT') | |
import com.hazelcast.config.Config | |
import com.hazelcast.config.NearCacheConfig | |
import com.hazelcast.core.Hazelcast | |
import com.hazelcast.core.HazelcastInstance | |
import java.util.concurrent.ConcurrentMap | |
import static com.hazelcast.config.PartitionGroupConfig.MemberGroupType.HOST_AWARE | |
import static com.hazelcast.instance.GroupProperties.* | |
import static java.util.concurrent.TimeUnit.SECONDS | |
Config multicastSetup() { | |
Config config = new Config() | |
//.setProperty(PROP_HEALTH_MONITORING_LEVEL, 'NOISY') | |
//.setProperty(PROP_INITIAL_MIN_CLUSTER_SIZE, '2') | |
.setProperty(PROP_VERSION_CHECK_ENABLED, 'false') | |
.setProperty(PROP_MC_URL_CHANGE_ENABLED, 'false') | |
.setProperty(PROP_MEMCACHE_ENABLED, 'false') | |
.setProperty(PROP_REST_ENABLED, 'false') | |
config.groupConfig | |
.setName('sessions') | |
.setPassword('sessionsX') | |
config.partitionGroupConfig | |
.setEnabled(true) | |
.setGroupType(HOST_AWARE) | |
config.networkConfig.join.multicastConfig | |
.setMulticastGroup('239.252.3.253') | |
.setMulticastPort(4446) | |
config.networkConfig.interfaces | |
.setEnabled(true) | |
.addInterface('172.28.124.*') | |
return config | |
} | |
Config config = multicastSetup() | |
HazelcastInstance h = Hazelcast.newHazelcastInstance(config) | |
ConcurrentMap<String, Object> map = h.getMap('sessions') | |
def readLine = { String label -> System.console().readLine(label).trim() } | |
while (true) { | |
[ | |
'\nMenu', | |
'-------', | |
'1. Put', | |
'2. Get', | |
'3. Remove', | |
'0. Quit' | |
].each { println it } | |
try { | |
switch (readLine('Your option: ')) { | |
case '0': | |
println 'Bye!' | |
h.shutdown() | |
System.exit 0 | |
case '1': | |
String key = readLine('key: ') | |
String val = readLine('val: ') | |
map.putAsync(key, val).get(5, SECONDS) | |
break | |
case '2': | |
String key = readLine('key: ') | |
String val = map.getAsync(key).get(5, SECONDS) | |
println val | |
break | |
case '3': | |
String key = readLine('key: ') | |
map.removeAsync(key).get(5, SECONDS) | |
break | |
} | |
} catch (e) { | |
println "Error: $e.message" | |
e.printStackTrace() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment