sangyun-han

[ONOS-4214]Implement NewDefaultDistributedQueueBuilder

- Revise incomplete method(queueBuilder) in StorageManager

Change-Id: I16cc1eb02fa01a4762fecc3c3c0472555fb45d04
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.store.primitives.impl;
17 +
18 +import org.onosproject.store.primitives.DistributedPrimitiveCreator;
19 +import org.onosproject.store.service.DistributedQueue;
20 +import org.onosproject.store.service.DistributedQueueBuilder;
21 +import org.onosproject.store.service.Serializer;
22 +
23 +import static com.google.common.base.Preconditions.checkArgument;
24 +import static com.google.common.base.Preconditions.checkState;
25 +
26 +/**
27 + * Default implementation of a {@code DistributedQueueBuilder}.
28 + *
29 + * @param <E> queue entry type
30 + */
31 +public class NewDefaultDistributedQueueBuilder<E> implements DistributedQueueBuilder<E> {
32 +
33 + private final DistributedPrimitiveCreator primitiveCreator;
34 + private String name;
35 + private boolean persistenceEnabled = true;
36 + private boolean metering = true;
37 + private Serializer serializer;
38 +
39 + public NewDefaultDistributedQueueBuilder(DistributedPrimitiveCreator primitiveCreator) {
40 + this.primitiveCreator = primitiveCreator;
41 + }
42 +
43 + @Override
44 + public DistributedQueueBuilder<E> withName(String name) {
45 + checkArgument(name != null && !name.isEmpty());
46 + this.name = name;
47 + return this;
48 + }
49 +
50 + @Override
51 + public DistributedQueueBuilder<E> withSerializer(Serializer serializer) {
52 + checkArgument(serializer != null);
53 + this.serializer = serializer;
54 + return this;
55 + }
56 +
57 + @Override
58 + public DistributedQueueBuilder<E> withMeteringDisabled() {
59 + metering = false;
60 + return this;
61 + }
62 +
63 + @Override
64 + public DistributedQueueBuilder<E> withPersistenceDisabled() {
65 + persistenceEnabled = false;
66 + return this;
67 + }
68 +
69 + private boolean validInputs() {
70 + return name != null && serializer != null;
71 + }
72 +
73 + @Override
74 + public DistributedQueue<E> build() {
75 + checkState(validInputs());
76 + return primitiveCreator.newDistributedQueue(name, serializer);
77 + }
78 +}
...@@ -141,8 +141,7 @@ public class StorageManager implements StorageService, StorageAdminService { ...@@ -141,8 +141,7 @@ public class StorageManager implements StorageService, StorageAdminService {
141 @Override 141 @Override
142 public <E> DistributedQueueBuilder<E> queueBuilder() { 142 public <E> DistributedQueueBuilder<E> queueBuilder() {
143 checkPermission(STORAGE_WRITE); 143 checkPermission(STORAGE_WRITE);
144 - // TODO: implement 144 + return new NewDefaultDistributedQueueBuilder<>(federatedPrimitiveCreator);
145 - throw new UnsupportedOperationException();
146 } 145 }
147 146
148 @Override 147 @Override
......