| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
|
| 20 |
package pubsub; |
| 21 |
|
| 22 |
import java.util.concurrent.TimeUnit; |
| 23 |
import org.apache.curator.x.async.modeled.JacksonModelSerializer; |
| 24 |
import org.apache.curator.x.async.modeled.ModelSpec; |
| 25 |
import org.apache.curator.x.async.modeled.ModelSpecBuilder; |
| 26 |
import org.apache.curator.x.async.modeled.ModeledFramework; |
| 27 |
import org.apache.curator.x.async.modeled.typed.TypedModeledFramework; |
| 28 |
import org.apache.curator.x.async.modeled.typed.TypedModeledFramework2; |
| 29 |
import org.apache.zookeeper.CreateMode; |
| 30 |
import pubsub.messages.LocationAvailable; |
| 31 |
import pubsub.messages.UserCreated; |
| 32 |
import pubsub.models.Group; |
| 33 |
import pubsub.models.Instance; |
| 34 |
import pubsub.models.InstanceType; |
| 35 |
import pubsub.models.Priority; |
| 36 |
|
| 37 |
public class Clients { |
| 38 |
/** |
| 39 |
* A client template for LocationAvailable instances |
| 40 |
*/ |
| 41 |
public static final TypedModeledFramework2<LocationAvailable, Group, Priority> locationAvailableClient = |
| 42 |
TypedModeledFramework2.from( |
| 43 |
ModeledFramework.builder(), |
| 44 |
builder(LocationAvailable.class), |
| 45 |
"/root/pubsub/messages/locations/{group}/{priority}/{id}"); |
| 46 |
|
| 47 |
/** |
| 48 |
* A client template for UserCreated instances |
| 49 |
*/ |
| 50 |
public static final TypedModeledFramework2<UserCreated, Group, Priority> userCreatedClient = |
| 51 |
TypedModeledFramework2.from( |
| 52 |
ModeledFramework.builder(), |
| 53 |
builder(UserCreated.class), |
| 54 |
"/root/pubsub/messages/users/{group}/{priority}/{id}"); |
| 55 |
|
| 56 |
/** |
| 57 |
* A client template for Instance instances |
| 58 |
*/ |
| 59 |
public static final TypedModeledFramework<Instance, InstanceType> instanceClient = TypedModeledFramework.from( |
| 60 |
ModeledFramework.builder(), builder(Instance.class), "/root/pubsub/instances/{instance-type}/{id}"); |
| 61 |
|
| 62 |
private static <T> ModelSpecBuilder<T> builder(Class<T> clazz) { |
| 63 |
return ModelSpec.builder(JacksonModelSerializer.build(clazz)) |
| 64 |
.withTtl(TimeUnit.MINUTES.toMillis(10)) // for our pub-sub example, messages are valid for 10 minutes |
| 65 |
.withCreateMode(CreateMode.PERSISTENT_WITH_TTL); |
| 66 |
} |
| 67 |
|
| 68 |
private Clients() {} |
| 69 |
} |