Skip to content

Commit

Permalink
JAV-57 added javadocs to help readers understand the code
Browse files Browse the repository at this point in the history
  • Loading branch information
seanyinx committed Jun 12, 2017
1 parent 2afddc6 commit a0af592
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,35 @@
*/
package io.servicecomb.company.worker;

/**
* {@link FibonacciEndpoint} provides the common interface for different endpoint implementations,
* such as {@link FibonacciRestEndpoint} and {@link FibonacciRpcEndpoint}.
*
* It supports sequence up to roughly 90, because the sequence value will exceed the limit of Java
* type long.
*
* The endpoints are supposed to be very thin. They parse requests from different protocols and
* delegate them to the same calculation logic provided by {@link FibonacciService}.
*/
public interface FibonacciEndpoint {

/**
* Calculates the nth term of fibonacci sequence.
* for example, the following statement outputs fibonacci sequence [0, 1, 1, 2, 3, 5]
* <pre>
* {@code long[] sequence = {
* endpoint.term(0),
* endpoint.term(1),
* endpoint.term(2),
* endpoint.term(3),
* endpoint.term(4),
* endpoint.term(5)};
* System.out.println(Arrays.toString(sequence));
* }
* </pre>
*
* @param n the index of fibonacci sequence
* @return the nth term of fibonacci
*/
long term(int n);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* {@link FibonacciRestEndpoint} provides the rest implementation of {@link FibonacciEndpoint}.
* The rest endpoint is accessed by /fibonacci/term?n={value} with HTTP GET.
*/
@RestSchema(schemaId = "fibonacciRestEndpoint")
@RequestMapping("/fibonacci")
@Controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import io.servicecomb.provider.pojo.RpcSchema;
import org.springframework.beans.factory.annotation.Autowired;


/**
* {@link FibonacciRpcEndpoint} provides the RPC implementation of {@link FibonacciEndpoint}.
*/
@RpcSchema(schemaId = "fibonacciRpcEndpoint")
// class modifier has to be public, or producer invoker will fail to access it
public class FibonacciRpcEndpoint implements FibonacciEndpoint {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.servicecomb.company.worker;/*
/*
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,8 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.servicecomb.company.worker;

/**
* {@link FibonacciService} provides the interface of actual fibonacci sequence calculation.
*/
interface FibonacciService {

/**
* @see FibonacciEndpoint#term(int)
* @param n the index of fibonacci sequence
* @return the nth term of fibonacci sequence
*/
long term(int n);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
@Service
class FibonacciServiceImpl implements FibonacciService {

/**
* {@inheritDoc}
*/
@Override
public long term(int n) {
if (n < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static void main(String[] args) {
SpringApplication.run(WorkerApplication.class, args);
}

// do not enable service registration/discovery and schema generation/registration
// unless the active profile is not dev
@EnableServiceComb
@Profile("!dev")
class ServiceCombConfig {
Expand Down

0 comments on commit a0af592

Please sign in to comment.