From 64581267895c11ab2810a25fb8b5a2dadfa6216f Mon Sep 17 00:00:00 2001 From: Luis Sanchez Date: Wed, 19 Apr 2017 16:23:46 -0400 Subject: [PATCH] [FAB-3263] remove ChaincodeBase.getChaincodeId() No longer needed. Change-Id: I991cf3d16b629030cfd92482ea1ebcdd843ff76f Signed-off-by: Luis Sanchez --- .../fabric/shim/ChaincodeBase.java | 33 +++++++++++-------- .../src/main/java/example/Example.java | 9 ++--- .../src/main/java/example/LinkExample.java | 5 --- .../src/main/java/example/MapExample.java | 5 --- .../src/main/java/example/RangeExample.java | 5 --- .../src/main/java/example/SimpleSample.java | 5 --- .../src/main/java/example/Example02.java | 7 ---- .../src/main/java/example/Example04.java | 5 --- .../src/main/java/example/Example05.java | 5 --- .../src/main/java/example/Example06.java | 5 --- .../src/main/java/example/EventSender.java | 6 ---- 11 files changed, 21 insertions(+), 69 deletions(-) diff --git a/core/chaincode/shim/java/src/main/java/org/hyperledger/fabric/shim/ChaincodeBase.java b/core/chaincode/shim/java/src/main/java/org/hyperledger/fabric/shim/ChaincodeBase.java index 0cf243a930a..81c677390b8 100644 --- a/core/chaincode/shim/java/src/main/java/org/hyperledger/fabric/shim/ChaincodeBase.java +++ b/core/chaincode/shim/java/src/main/java/org/hyperledger/fabric/shim/ChaincodeBase.java @@ -58,7 +58,6 @@ public abstract class ChaincodeBase implements Chaincode { private static Log logger = LogFactory.getLog(ChaincodeBase.class); - public abstract String getChaincodeID(); public static final String DEFAULT_HOST = "127.0.0.1"; public static final int DEFAULT_PORT = 7051; @@ -69,7 +68,7 @@ public abstract class ChaincodeBase implements Chaincode { private String rootCertFile = "/etc/hyperledger/fabric/peer.crt"; private Handler handler; - private String id = getChaincodeID(); + private String id; private final static String CORE_CHAINCODE_ID_NAME = "CORE_CHAINCODE_ID_NAME"; private final static String CORE_PEER_ADDRESS = "CORE_PEER_ADDRESS"; @@ -77,18 +76,24 @@ public abstract class ChaincodeBase implements Chaincode { private final static String CORE_PEER_TLS_SERVERHOSTOVERRIDE = "CORE_PEER_TLS_SERVERHOSTOVERRIDE"; private static final String CORE_PEER_TLS_ROOTCERT_FILE = "CORE_PEER_TLS_ROOTCERT_FILE"; - // Start entry point for chaincodes bootstrap. - public void start(String[] args) { - processEnvironmentOptions(); - processCommandLineOptions(args); - new Thread(() -> { - logger.trace("chaincode started"); - final ManagedChannel connection = newPeerClientConnection(); - logger.trace("connection created"); - chatWithPeer(connection); - logger.trace("chatWithPeer DONE"); - }).start(); - } + /** + * Start chaincode + * @param args command line arguments + */ + public void start(String[] args) { + processEnvironmentOptions(); + processCommandLineOptions(args); + if(this.id == null) { + logger.error(String.format("The chaincode id must be specified using either the -i or --i command line options or the %s environment variable.", CORE_CHAINCODE_ID_NAME)); + } + new Thread(() -> { + logger.trace("chaincode started"); + final ManagedChannel connection = newPeerClientConnection(); + logger.trace("connection created"); + chatWithPeer(connection); + logger.trace("chatWithPeer DONE"); + }).start(); + } private void processCommandLineOptions(String[] args) { Options options = new Options(); diff --git a/examples/chaincode/java/Example/src/main/java/example/Example.java b/examples/chaincode/java/Example/src/main/java/example/Example.java index 589ab1bfd9a..7abba26e966 100644 --- a/examples/chaincode/java/Example/src/main/java/example/Example.java +++ b/examples/chaincode/java/Example/src/main/java/example/Example.java @@ -17,10 +17,10 @@ package example; -import org.hyperledger.fabric.shim.ChaincodeBase; -import org.hyperledger.fabric.shim.ChaincodeStub; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.hyperledger.fabric.shim.ChaincodeBase; +import org.hyperledger.fabric.shim.ChaincodeStub; /** @@ -101,11 +101,6 @@ public String query(ChaincodeStub stub, String function, String[] args) { } } - @Override - public String getChaincodeID() { - return "hello"; - } - public static void main(String[] args) throws Exception { System.out.println("Hello world! starting "+args); log.info("starting"); diff --git a/examples/chaincode/java/LinkExample/src/main/java/example/LinkExample.java b/examples/chaincode/java/LinkExample/src/main/java/example/LinkExample.java index c38daedecdb..8218ff78b3a 100644 --- a/examples/chaincode/java/LinkExample/src/main/java/example/LinkExample.java +++ b/examples/chaincode/java/LinkExample/src/main/java/example/LinkExample.java @@ -76,9 +76,4 @@ public static void main(String[] args) throws Exception { new LinkExample().start(args); } - @Override - public String getChaincodeID() { - return "link"; - } - } diff --git a/examples/chaincode/java/MapExample/src/main/java/example/MapExample.java b/examples/chaincode/java/MapExample/src/main/java/example/MapExample.java index f60536230ac..b5cff88871a 100644 --- a/examples/chaincode/java/MapExample/src/main/java/example/MapExample.java +++ b/examples/chaincode/java/MapExample/src/main/java/example/MapExample.java @@ -49,11 +49,6 @@ public String query(ChaincodeStub stub, String function, String[] args) { return stub.getState(args[0]); } - @Override - public String getChaincodeID() { - return "map"; - } - public static void main(String[] args) throws Exception { new MapExample().start(args); } diff --git a/examples/chaincode/java/RangeExample/src/main/java/example/RangeExample.java b/examples/chaincode/java/RangeExample/src/main/java/example/RangeExample.java index cf1425c91e2..80f8892e375 100644 --- a/examples/chaincode/java/RangeExample/src/main/java/example/RangeExample.java +++ b/examples/chaincode/java/RangeExample/src/main/java/example/RangeExample.java @@ -71,11 +71,6 @@ public String query(ChaincodeStub stub, String function, String[] args) { } - @java.lang.Override - public String getChaincodeID() { - return "RangeExample"; - } - public static void main(String[] args) throws Exception { log.info("starting"); new RangeExample().start(args); diff --git a/examples/chaincode/java/SimpleSample/src/main/java/example/SimpleSample.java b/examples/chaincode/java/SimpleSample/src/main/java/example/SimpleSample.java index ac000dbd5d0..30f83ebb2d0 100644 --- a/examples/chaincode/java/SimpleSample/src/main/java/example/SimpleSample.java +++ b/examples/chaincode/java/SimpleSample/src/main/java/example/SimpleSample.java @@ -142,11 +142,6 @@ public Response query(ChaincodeStub stub, String function, String[] args) { } - @Override - public String getChaincodeID() { - return "SimpleSample"; - } - public static void main(String[] args) throws Exception { new SimpleSample().start(args); } diff --git a/examples/chaincode/java/chaincode_example02/src/main/java/example/Example02.java b/examples/chaincode/java/chaincode_example02/src/main/java/example/Example02.java index 6e9f5a569f4..aa8c2e43264 100644 --- a/examples/chaincode/java/chaincode_example02/src/main/java/example/Example02.java +++ b/examples/chaincode/java/chaincode_example02/src/main/java/example/Example02.java @@ -22,8 +22,6 @@ import static org.hyperledger.fabric.shim.ChaincodeHelper.newInternalServerErrorResponse; import static org.hyperledger.fabric.shim.ChaincodeHelper.newSuccessResponse; -import java.util.List; - import javax.json.Json; import org.apache.commons.logging.Log; @@ -155,11 +153,6 @@ private Response query(ChaincodeStub stub, String[] args) { } - @Override - public String getChaincodeID() { - return "Example02"; - } - public static void main(String[] args) throws Exception { new Example02().start(args); } diff --git a/examples/chaincode/java/chaincode_example04/src/main/java/example/Example04.java b/examples/chaincode/java/chaincode_example04/src/main/java/example/Example04.java index 53b754f8b9b..a6c7f75e032 100644 --- a/examples/chaincode/java/chaincode_example04/src/main/java/example/Example04.java +++ b/examples/chaincode/java/chaincode_example04/src/main/java/example/Example04.java @@ -150,11 +150,6 @@ private Response doInvoke(ChaincodeStub stub, String[] args) { return response; } - @Override - public String getChaincodeID() { - return "Example04"; - } - public static void main(String[] args) throws Exception { new Example04().start(args); } diff --git a/examples/chaincode/java/chaincode_example05/src/main/java/example/Example05.java b/examples/chaincode/java/chaincode_example05/src/main/java/example/Example05.java index 1ef1ce94230..f86153306a7 100644 --- a/examples/chaincode/java/chaincode_example05/src/main/java/example/Example05.java +++ b/examples/chaincode/java/chaincode_example05/src/main/java/example/Example05.java @@ -129,11 +129,6 @@ private Response doInvoke(ChaincodeStub stub, String[] args) { return newSuccessResponse(String.valueOf(sum).getBytes(UTF_8)); } - @Override - public String getChaincodeID() { - return "Example05"; - } - public static void main(String[] args) throws Exception { new Example05().start(args); } diff --git a/examples/chaincode/java/chaincode_example06/src/main/java/example/Example06.java b/examples/chaincode/java/chaincode_example06/src/main/java/example/Example06.java index f60cca5f20c..b58e5cd5439 100644 --- a/examples/chaincode/java/chaincode_example06/src/main/java/example/Example06.java +++ b/examples/chaincode/java/chaincode_example06/src/main/java/example/Example06.java @@ -42,11 +42,6 @@ public Response invoke(ChaincodeStub stub) { return newBadRequestResponse(format("Invalid arguments specified")); } } - - @Override - public String getChaincodeID() { - return "Example06"; - } public static void main(String[] args) throws Exception { new Example06().start(args); diff --git a/examples/chaincode/java/eventsender/src/main/java/example/EventSender.java b/examples/chaincode/java/eventsender/src/main/java/example/EventSender.java index 6bdcee70d21..bcf4f21c09a 100644 --- a/examples/chaincode/java/eventsender/src/main/java/example/EventSender.java +++ b/examples/chaincode/java/eventsender/src/main/java/example/EventSender.java @@ -19,7 +19,6 @@ import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; import static org.hyperledger.fabric.shim.ChaincodeHelper.newBadRequestResponse; import static org.hyperledger.fabric.shim.ChaincodeHelper.newInternalServerErrorResponse; import static org.hyperledger.fabric.shim.ChaincodeHelper.newSuccessResponse; @@ -82,11 +81,6 @@ private Response doQuery(ChaincodeStub stub) { return newSuccessResponse(String.format("{\"NoEvents\":%d}", Integer.parseInt(stub.getStringState(EVENT_COUNT)))); } - @Override - public String getChaincodeID() { - return "EventSender"; - } - public static void main(String[] args) throws Exception { new EventSender().start(args); }