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