Created
February 20, 2015 08:34
-
-
Save enesakar/3a7594c83f1b27fbc202 to your computer and use it in GitHub Desktop.
hazelcast regex predicate example
This file contains hidden or 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
| public class Main { | |
| public static void main(String[] args) { | |
| final HazelcastInstance hz = Hazelcast.newHazelcastInstance(null); | |
| IMap employees = hz.getMap("employees"); | |
| employees.put(1, new Employee("xxx zz yyy")); | |
| employees.put(2, new Employee("aaa bb ccc")); | |
| Collection<Employee> result = employees.values(Predicates.regex("employeeName", "x+.*")); | |
| for (Employee employee : result) { | |
| System.out.println(employee.employeeName); | |
| } | |
| } | |
| static class Employee implements Serializable{ | |
| String employeeName; | |
| Employee(String employeeName) { | |
| this.employeeName = employeeName; | |
| } | |
| } | |
| } |
Hi,
I saw your questions on Hazelcast Groups.
Ideally you want to have the Employee class available on a server classpath. If that's not possible then the Employee class has to implement Portable interface - with this interface is possible to run queries even when the class is not available on a classpath.
Thanks for your comment! I'll look into the Hazelcast's Portable interface.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the example. This works when the Employee class is defined on the Hazelcast server. In our application, this class would be defined in the Client and the memory cache will be used to store the serialized Employee object as the Value part of a KV pair. All Keys will be strings. We want to be able to query a map in the cache (from the Client), by passing in a filter or a regex for the Keys in that map. A collection of Key strings would be returned based on that filter.
If the above example was executed on the Client (replace line 4 by the following), what would then be the attribute in the Predicates.regex method?
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
IMap employees = client.getMap("employees");
Thanks again for your help.