execute_on_members(members, task)Executes a task on each of the specified members.
| Parameters: |
|
|---|---|
| Returns: | (Map), |
(The online version, http://hazelcast.github.io/hazelcast-python-client/, is broken BTW )import hazelcast
import logging
from hazelcast.serialization.api import IdentifiedDataSerializable
class CollectData(IdentifiedDataSerializable):
CLASS_ID = 12
FACTORY_ID = 3
def __init__(self, propertyKey):
self.propertyKey = propertyKey
def write_data(self, out):
out.write_utf(self.propertyKey)
def get_factory_id(self):
return self.FACTORY_ID
def get_class_id(self):
return self.CLASS_ID
if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s', datefmt="%H:%M%:%S,")
logging.getLogger().setLevel(logging.INFO)
logger = logging.getLogger("main")
config = hazelcast.ClientConfig()
config.group_config.name = "dev"
config.group_config.password = "dev-pass"
config.network_config.addresses.append('127.0.0.1')
identifiedDataSerializable_factory = {CollectData.CLASS_ID: CollectData}
config.serialization_config.add_data_serializable_factory(CollectData.FACTORY_ID, identifiedDataSerializable_factory)
client = hazelcast.HazelcastClient(config)
executor = client.get_executor("my-exec")
results = executor.execute_on_all_members(CollectData("java.vm.name"))
for result in results.result():
print ">", result
Java side of this should look like as following:
import com.hazelcast.config.Config;
import com.hazelcast.config.SerializationConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.DataSerializableFactory;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import java.io.IOException;
import java.util.concurrent.Callable;
class CollectData implements IdentifiedDataSerializable, Callable<String> {
public static int CLASS_ID = 12;
private String propertyKey;
CollectData() {
}
CollectData(String propertyKey) {
this.propertyKey = propertyKey;
}
public int getFactoryId() {
return 3;
}
public int getId() {
return 12;
}
public void writeData(ObjectDataOutput out) throws IOException {
out.writeUTF(propertyKey);
}
public void readData(ObjectDataInput in) throws IOException {
propertyKey = in.readUTF();
}
public String call() throws Exception {
return System.getProperty(propertyKey);
}
}
public class XServer {
public static void main(String[] args) {
Config config = new Config();
SerializationConfig serializationConfig = config.getSerializationConfig();
serializationConfig.addDataSerializableFactory(3, new DataSerializableFactory() {
public IdentifiedDataSerializable create(int typeId) {
if (CollectData.CLASS_ID == typeId) {
return new CollectData();
}
return null;
}
});
Hazelcast.newHazelcastInstance(config);
}
}
--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/f1bb8b51-eaaa-408e-93f0-88d7bf1eab18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.