blob: f7fcfc1544342e29408358373ca94484749da599 [file] [log] [blame]
Jian Li7eb20782021-02-27 01:10:50 +09001/*
2 * Copyright 2021-present Open Networking Foundation
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 */
16package org.onosproject.kubevirtnetworking.api;
17
18import com.fasterxml.jackson.databind.ObjectMapper;
19import org.onlab.osgi.DefaultServiceDirectory;
20import org.onlab.osgi.ServiceDirectory;
21import org.onosproject.codec.CodecContext;
22import org.onosproject.codec.CodecService;
23import org.onosproject.codec.JsonCodec;
24
25/**
26 * Abstract watcher.
27 */
28public class AbstractWatcher implements CodecContext {
29
30 private static ServiceDirectory services = new DefaultServiceDirectory();
31 private final ObjectMapper mapper = new ObjectMapper();
32
33 @Override
34 public ObjectMapper mapper() {
35 return mapper;
36 }
37
38 @Override
39 public <T> JsonCodec<T> codec(Class<T> entityClass) {
40 return services.get(CodecService.class).getCodec(entityClass);
41 }
42
43 @Override
44 public <T> T getService(Class<T> serviceClass) {
45 return services.get(serviceClass);
46 }
47}