001/*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.hadoop.hbase.coprocessor;
021
022import com.google.protobuf.Service;
023import org.apache.yetus.audience.InterfaceAudience;
024
025import java.util.Collections;
026
027/**
028 * Classes to help maintain backward compatibility with now deprecated {@link CoprocessorService}
029 * and {@link SingletonCoprocessorService}.
030 * From 2.0 onwards, implementors of coprocessor service should also implement the relevant
031 * coprocessor class (For eg {@link MasterCoprocessor} for coprocessor service in master), and
032 * override get*Service() method to return the {@link com.google.protobuf.Service} object.
033 * To maintain backward compatibility with 1.0 implementation, we'll wrap implementation of
034 * CoprocessorService/SingletonCoprocessorService in the new
035 * {Master, Region, RegionServer}Coprocessor class.
036 * Since there is no backward compatibility guarantee for Observers, we leave get*Observer() to
037 * default which returns null.
038 * This approach to maintain backward compatibility seems cleaner and more explicit.
039 */
040@InterfaceAudience.Private
041@Deprecated
042public class CoprocessorServiceBackwardCompatiblity {
043
044  static public class MasterCoprocessorService implements MasterCoprocessor {
045
046    CoprocessorService service;
047
048    public MasterCoprocessorService(CoprocessorService service) {
049      this.service = service;
050    }
051
052    @Override
053    public Iterable<Service> getServices() {
054      return Collections.singleton(service.getService());
055    }
056  }
057
058  static public class RegionCoprocessorService implements RegionCoprocessor {
059
060    CoprocessorService service;
061
062    public RegionCoprocessorService(CoprocessorService service) {
063      this.service = service;
064    }
065
066    @Override
067    public Iterable<Service> getServices() {
068      return Collections.singleton(service.getService());
069    }
070  }
071
072  static public class RegionServerCoprocessorService implements RegionServerCoprocessor {
073
074    SingletonCoprocessorService service;
075
076    public RegionServerCoprocessorService(SingletonCoprocessorService service) {
077      this.service = service;
078    }
079
080    @Override
081    public Iterable<Service> getServices() {
082      return Collections.singleton(service.getService());
083    }
084  }
085}
086