Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<perf>(jni): perf jni code fommat. #220

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bindings/java/jni/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ println("Notice: current gradle version is " + gradle.gradleVersion)
sourceCompatibility = 1.8
targetCompatibility = 1.8

googleJavaFormat {
toolVersion = '1.7'
options style: 'AOSP'
source = sourceSets*.allJava
include '**/*.java'
}

[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'

repositories {
Expand All @@ -25,7 +32,6 @@ repositories {
dependencies {
api ('org.slf4j:slf4j-api:1.7.36')
api ('com.fasterxml.jackson.core:jackson-databind:2.14.2')
implementation 'org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:2.9.1'
testCompile ('org.slf4j:slf4j-log4j12:1.7.36')
testCompile ('junit:junit:4.13.2')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,80 +21,80 @@

public class BcosSDKJniObj {

private static final Logger logger = LoggerFactory.getLogger(BcosSDKJniObj.class);

static {
JniLibLoader.loadJniLibrary();
}

protected BcosSDKJniObj() {}

/**
* @param jniConfig
* @return
*/
public static BcosSDKJniObj build(JniConfig jniConfig) throws JniException {
long nativePointer = create(jniConfig);
BcosSDKJniObj bcosSDKJniObj = new BcosSDKJniObj();
bcosSDKJniObj.setNativePointer(nativePointer);
logger.info("newNativePointer, nativePointer: {}, jniConfig: {}", nativePointer, jniConfig);
return bcosSDKJniObj;
}

/**
* destroy interface
*
* @param nativePointer
*/
public static void destroy(long nativePointer) {
if (nativePointer != 0L) {
BcosSDKJniObj bcosSDKJniObj = new BcosSDKJniObj();
bcosSDKJniObj.setNativePointer(nativePointer);
bcosSDKJniObj.destroy();
private static final Logger logger = LoggerFactory.getLogger(BcosSDKJniObj.class);

static {
JniLibLoader.loadJniLibrary();
}
}

private long nativePointer = 0L;
protected BcosSDKJniObj() {}

/**
* @param jniConfig
* @return
*/
public static BcosSDKJniObj build(JniConfig jniConfig) throws JniException {
long nativePointer = create(jniConfig);
BcosSDKJniObj bcosSDKJniObj = new BcosSDKJniObj();
bcosSDKJniObj.setNativePointer(nativePointer);
logger.info("newNativePointer, nativePointer: {}, jniConfig: {}", nativePointer, jniConfig);
return bcosSDKJniObj;
}

public long getNativePointer() {
return nativePointer;
}
/**
* destroy interface
*
* @param nativePointer
*/
public static void destroy(long nativePointer) {
if (nativePointer != 0L) {
BcosSDKJniObj bcosSDKJniObj = new BcosSDKJniObj();
bcosSDKJniObj.setNativePointer(nativePointer);
bcosSDKJniObj.destroy();
}
}

private void setNativePointer(long nativePointer) {
this.nativePointer = nativePointer;
}
private long nativePointer = 0L;

public static int localProtocolInfo(long nativePointer) {
BcosSDKJniObj bcosSDKJniObj = new BcosSDKJniObj();
bcosSDKJniObj.setNativePointer(nativePointer);
return bcosSDKJniObj.localProtocolInfo();
}
public long getNativePointer() {
return nativePointer;
}

public static int negotiatedProtocolInfo(long nativePointer) {
BcosSDKJniObj bcosSDKJniObj = new BcosSDKJniObj();
bcosSDKJniObj.setNativePointer(nativePointer);
return bcosSDKJniObj.negotiatedProtocolInfo();
}
private void setNativePointer(long nativePointer) {
this.nativePointer = nativePointer;
}

public static int localProtocolInfo(long nativePointer) {
BcosSDKJniObj bcosSDKJniObj = new BcosSDKJniObj();
bcosSDKJniObj.setNativePointer(nativePointer);
return bcosSDKJniObj.localProtocolInfo();
}

public static int negotiatedProtocolInfo(long nativePointer) {
BcosSDKJniObj bcosSDKJniObj = new BcosSDKJniObj();
bcosSDKJniObj.setNativePointer(nativePointer);
return bcosSDKJniObj.negotiatedProtocolInfo();
}

// ------------------------native method list-------------------------------------------
// ------------------------native method list-------------------------------------------

public static native long create(JniConfig config);
public static native long create(JniConfig config);

public native void start();
public native void start();

public native void stop();
public native void stop();

public native void destroy();
public native void destroy();

public native int localProtocolInfo();
public native int localProtocolInfo();

public native int negotiatedProtocolInfo();
public native int negotiatedProtocolInfo();

// -------------------------native method end-------------------------------------------
// -------------------------native method end-------------------------------------------

// ------------------------ block notifier begin----------------------------------------
// ------------------------ block notifier begin----------------------------------------

public native void registerBlockNotifier(String group, BlockNotifier callback);
public native void registerBlockNotifier(String group, BlockNotifier callback);

// ------------------------ block notifier end------------------------------------------
// ------------------------ block notifier end------------------------------------------
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.math.BigInteger;

public interface BlockNotifier {
/**
* receive block notifier
*
* @param groupId
* @param blockNumber
* @return void
*/
void onResponse(String groupId, BigInteger blockNumber);
/**
* receive block notifier
*
* @param groupId
* @param blockNumber
* @return void
*/
void onResponse(String groupId, BigInteger blockNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,55 @@
import org.slf4j.LoggerFactory;

public class AmopJniObj {
private static final Logger logger = LoggerFactory.getLogger(AmopJniObj.class);
private static final Logger logger = LoggerFactory.getLogger(AmopJniObj.class);

/**
* @param nativePointer
* @return
* @throws JniException
*/
public static AmopJniObj build(long nativePointer) {
AmopJniObj amop = new AmopJniObj();
amop.setNativePointer(nativePointer);
/**
* @param nativePointer
* @return
* @throws JniException
*/
public static AmopJniObj build(long nativePointer) {
AmopJniObj amop = new AmopJniObj();
amop.setNativePointer(nativePointer);

logger.info(" nativePointer: {}", nativePointer);
return amop;
}
logger.info(" nativePointer: {}", nativePointer);
return amop;
}

private AmopJniObj() {}
private AmopJniObj() {}

private long nativePointer = 0L;
private long nativePointer = 0L;

public long getNativePointer() {
return nativePointer;
}
public long getNativePointer() {
return nativePointer;
}

private void setNativePointer(long nativePointer) {
this.nativePointer = nativePointer;
}
private void setNativePointer(long nativePointer) {
this.nativePointer = nativePointer;
}

// ----------------------------- Amop interface begin --------------------------------------
// ----------------------------- Amop interface begin --------------------------------------

public native void start();
public native void start();

public native void stop();
public native void stop();

public native void subscribeTopic(Set<String> topicsName);
public native void subscribeTopic(Set<String> topicsName);

public native void subscribeTopic(String topicName, AmopRequestCallback callback);
public native void subscribeTopic(String topicName, AmopRequestCallback callback);

public native void unsubscribeTopic(Set<String> topicsName);
public native void unsubscribeTopic(Set<String> topicsName);

public native void setCallback(AmopRequestCallback cb);
public native void setCallback(AmopRequestCallback cb);

public native void sendAmopMsg(
String topic, byte[] data, int timeout, AmopResponseCallback callback);
public native void sendAmopMsg(
String topic, byte[] data, int timeout, AmopResponseCallback callback);

public native void broadcastAmopMsg(String topic, byte[] data);
public native void broadcastAmopMsg(String topic, byte[] data);

public native void sendResponse(String endPoint, String seq, byte[] data);
public native void sendResponse(String endPoint, String seq, byte[] data);

public native Set<String> getSubTopics();
public native Set<String> getSubTopics();

// ----------------------------- Amop interface end --------------------------------------
// ----------------------------- Amop interface end --------------------------------------
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
package org.fisco.bcos.sdk.jni.amop;

public interface AmopRequestCallback {
/**
* recieve amop request message
*
* @param endpoint
* @param seq
* @param data
* @return void
*/
void onRequest(String endpoint, String seq, byte[] data);
/**
* recieve amop request message
*
* @param endpoint
* @param seq
* @param data
* @return void
*/
void onRequest(String endpoint, String seq, byte[] data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.fisco.bcos.sdk.jni.common.Response;

public interface AmopResponseCallback {
void onResponse(Response response);
void onResponse(Response response);
}
Loading
Loading