Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 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 org.apache.thrift.server;
21
 
22
import org.apache.thrift.TProcessorFactory;
23
import org.apache.thrift.protocol.TBinaryProtocol;
24
import org.apache.thrift.protocol.TProtocolFactory;
25
import org.apache.thrift.transport.TServerTransport;
26
import org.apache.thrift.transport.TTransportFactory;
27
 
28
/**
29
 * Generic interface for a Thrift server.
30
 *
31
 */
32
public abstract class TServer {
33
 
34
  /**
35
   * Core processor
36
   */
37
  protected TProcessorFactory processorFactory_;
38
 
39
  /**
40
   * Server transport
41
   */
42
  protected TServerTransport serverTransport_;
43
 
44
  /**
45
   * Input Transport Factory
46
   */
47
  protected TTransportFactory inputTransportFactory_;
48
 
49
  /**
50
   * Output Transport Factory
51
   */
52
  protected TTransportFactory outputTransportFactory_;
53
 
54
  /**
55
   * Input Protocol Factory
56
   */
57
  protected TProtocolFactory inputProtocolFactory_;
58
 
59
  /**
60
   * Output Protocol Factory
61
   */
62
  protected TProtocolFactory outputProtocolFactory_;
63
 
64
  /**
65
   * Default constructors.
66
   */
67
 
68
  protected TServer(TProcessorFactory processorFactory,
69
                    TServerTransport serverTransport) {
70
    this(processorFactory,
71
         serverTransport,
72
         new TTransportFactory(),
73
         new TTransportFactory(),
74
         new TBinaryProtocol.Factory(),
75
         new TBinaryProtocol.Factory());
76
  }
77
 
78
  protected TServer(TProcessorFactory processorFactory,
79
                    TServerTransport serverTransport,
80
                    TTransportFactory transportFactory) {
81
    this(processorFactory,
82
         serverTransport,
83
         transportFactory,
84
         transportFactory,
85
         new TBinaryProtocol.Factory(),
86
         new TBinaryProtocol.Factory());
87
  }
88
 
89
  protected TServer(TProcessorFactory processorFactory,
90
                    TServerTransport serverTransport,
91
                    TTransportFactory transportFactory,
92
                    TProtocolFactory protocolFactory) {
93
    this(processorFactory,
94
         serverTransport,
95
         transportFactory,
96
         transportFactory,
97
         protocolFactory,
98
         protocolFactory);
99
  }
100
 
101
  protected TServer(TProcessorFactory processorFactory,
102
                    TServerTransport serverTransport,
103
                    TTransportFactory inputTransportFactory,
104
                    TTransportFactory outputTransportFactory,
105
                    TProtocolFactory inputProtocolFactory,
106
                    TProtocolFactory outputProtocolFactory) {
107
    processorFactory_ = processorFactory;
108
    serverTransport_ = serverTransport;
109
    inputTransportFactory_ = inputTransportFactory;
110
    outputTransportFactory_ = outputTransportFactory;
111
    inputProtocolFactory_ = inputProtocolFactory;
112
    outputProtocolFactory_ = outputProtocolFactory;
113
  }
114
 
115
  /**
116
   * The run method fires up the server and gets things going.
117
   */
118
  public abstract void serve();
119
 
120
  /**
121
   * Stop the server. This is optional on a per-implementation basis. Not
122
   * all servers are required to be cleanly stoppable.
123
   */
124
  public void stop() {}
125
 
126
}