Skip to content

Commit

Permalink
Merge pull request #47 from Liuchy1/master
Browse files Browse the repository at this point in the history
modify client config class
  • Loading branch information
Liuchy1 committed Dec 16, 2015
2 parents 8b563e2 + e2c027a commit ad352bc
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 72 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@
config.setConnectionTimeout(10 * 1000); // 10 seconds
config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2

ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000); // 30 seconds

JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
}

Expand Down
12 changes: 2 additions & 10 deletions example/main/java/cn/jpush/api/examples/ClientExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ public class ClientExample {
protected static final Logger LOG = LoggerFactory.getLogger(ClientExample.class);

private static final String appKey = "dd1066407b044738b6479275";
private static final String masterSecret = "6b135be0037a5c1e693c3dfa";
private static final String TAG1 = "tag1";
private static final String ALIAS1 = "alias1";
private static final String ALIAS2 = "alias2";
private static final String REGISTRATION_ID1 = "0900e8d85ef";
private static final String REGISTRATION_ID2 = "0a04ad7d8b4";

private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";

public static void main(String[] args) {
// testDefaultClient();
// testCustomClient();
testCustomPushClient();
// testCustomPushClient();
}

public static void testDefaultClient() {
Expand All @@ -35,8 +29,6 @@ public static void testCustomClient() {
config.setConnectionTimeout(10 * 1000); // 10 seconds
config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2

ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000); // 30 seconds

JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
}

Expand Down
2 changes: 1 addition & 1 deletion example/main/java/cn/jpush/api/examples/DeviceExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DeviceExample {
protected static final Logger LOG = LoggerFactory.getLogger(DeviceExample.class);

private static final String appKey = "dd1066407b044738b6479275";
private static final String masterSecret = "6b135be0037a5c1e693c3dfa";
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
private static final String TAG1 = "tag1";
private static final String ALIAS1 = "alias1";
private static final String ALIAS2 = "alias2";
Expand Down
4 changes: 2 additions & 2 deletions example/main/java/cn/jpush/api/examples/PushExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class PushExample {
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);

// demo App defined in resources/jpush-api.conf
private static final String appKey ="e5c0d34f58732cf09b2d4d74";
private static final String masterSecret = "4cdda6d3c8b029941dbc5cb3";
private static final String appKey ="dd1066407b044738b6479275";
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";

public static final String TITLE = "Test from API example";
public static final String ALERT = "Test from API Example - alert";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ReportsExample {

// demo App defined in resources/jpush-api.conf
private static final String appKey = "dd1066407b044738b6479275";
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";

public static void main(String[] args) {
testGetReport();
Expand Down
4 changes: 2 additions & 2 deletions example/main/java/cn/jpush/api/examples/ScheduleExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class ScheduleExample {

protected static final Logger LOG = LoggerFactory.getLogger(ScheduleExample.class);

private static final String appKey ="e5c0d34f58732cf09b2d4d74";
private static final String masterSecret = "4cdda6d3c8b029941dbc5cb3";
private static final String appKey ="dd1066407b044738b6479275";
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";

public static void main(String[] args) {

Expand Down
67 changes: 13 additions & 54 deletions src/main/java/cn/jpush/api/common/ClientConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.jpush.api.common;

import java.util.HashMap;
import java.util.Map;

public class ClientConfig extends HashMap<String, Object> {

Expand Down Expand Up @@ -117,80 +116,48 @@ public static ClientConfig getInstance() {
return instance;
}

public static void setDeviceHostName(Map conf, String hostName) {
conf.put(DEVICE_HOST_NAME, hostName);
}

/**
* Setup custom device api host name, if using the JPush privacy cloud.
* @param hostName the custom api host name, default is JPush domain name
*/
public void setDeviceHostName(String hostName) {
setDeviceHostName(this, hostName);
}

public static void setPushHostName(Map conf, String hostName) {
conf.put(PUSH_HOST_NAME, hostName);
this.put(DEVICE_HOST_NAME, hostName);
}

/**
* Setup custom push api host name, if using the JPush privacy cloud.
* @param hostName the custom api host name, default is JPush domain name
*/
public void setPushHostName(String hostName) {
setPushHostName(this, hostName);
}

public static void setReportHostName(Map conf, String hostName) {
conf.put(REPORT_HOST_NAME, hostName);
this.put(PUSH_HOST_NAME, hostName);
}

/**
* Setup custom report api host name, if using the JPush privacy cloud.
* @param hostName the custom api host name, default is JPush domain name
*/
public void setReportHostName(String hostName) {
setReportHostName(this, hostName);
}

public static void setScheduleHostName(Map conf, String hostName) {
conf.put(SCHEDULE_HOST_NAME, hostName);
this.put(REPORT_HOST_NAME, hostName);
}

public void setScheduleHostName(String hostName) {
setScheduleHostName(this, hostName);
this.put(SCHEDULE_HOST_NAME, hostName);
}

public void setSSLVersion(String sslVer) {
setSSLVersion(this, sslVer);
}

public static void setSSLVersion(Map conf, String sslVer) {
conf.put(SSL_VERSION, sslVer);
this.put(SSL_VERSION, sslVer);
}

public void setMaxRetryTimes(int maxRetryTimes) {
setMaxRetryTimes(this, maxRetryTimes);
}

public static void setMaxRetryTimes(Map conf, int maxRetryTimes) {
conf.put(MAX_RETRY_TIMES, maxRetryTimes);
this.put(MAX_RETRY_TIMES, maxRetryTimes);
}

public void setReadTimeout(int readTimeout) {
setReadTimeout(this, readTimeout);
}

public static void setReadTimeout(Map conf, int readTimeout) {
conf.put(READ_TIMEOUT, readTimeout);
this.put(READ_TIMEOUT, readTimeout);
}

public void setConnectionTimeout(int connectionTimeout) {
setConnectionTimeout(this, connectionTimeout);
}

public static void setConnectionTimeout(Map conf, int connectionTimeout) {
conf.put(CONNECTION_TIMEOUT, connectionTimeout);
this.put(CONNECTION_TIMEOUT, connectionTimeout);
}

public String getSSLVersion() {
Expand All @@ -209,28 +176,20 @@ public Integer getConnectionTimeout() {
return (Integer) this.get(CONNECTION_TIMEOUT);
}

public static void setApnsProduction(Map conf, boolean production) {
public void setApnsProduction(boolean production) {
if(production) {
conf.put(APNS_PRODUCTION, 1);
this.put(APNS_PRODUCTION, 1);
} else {
conf.put(APNS_PRODUCTION, 0);
this.put(APNS_PRODUCTION, 0);
}
}

public void setApnsProduction(boolean production) {
setApnsProduction(this, production);
}

public static void setTimeToLive(Map conf, long timeToLive) {
conf.put(TIME_TO_LIVE, timeToLive);
}

public void setTimeToLive(long timeToLive) {
setTimeToLive(this, timeToLive);
this.put(TIME_TO_LIVE, timeToLive);
}

public void setGlobalPushSetting(boolean apnsProduction, long timeToLive) {
setApnsProduction(this, apnsProduction);
setApnsProduction(apnsProduction);
setTimeToLive(timeToLive);
}
}

0 comments on commit ad352bc

Please sign in to comment.