Skip to content

Commit ce8d571

Browse files
author
Devendra
committed
Merge branch 'develop' of github.com:pubnub/java into develop
2 parents c4ceb42 + ca09971 commit ce8d571

12 files changed

Lines changed: 870 additions & 100 deletions

java/build.xml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<property environment="env"/>
55
<property name="pubnub_jar_file_name" value="Pubnub-StandardEdition-${VERSION}.jar"/>
66
<property name="pubnub_debug_jar_file_name" value="Pubnub-StandardEdition-Debug-${VERSION}.jar"/>
7-
<property name="pubnub_unittests_jar_file_name" value="Pubnub-UnitTests-${VERSION}.jar"/>
87
<property name="srcPubnubApi.link" value="srcPubnubApi"/>
98
<property name="sources_pubnub_api" value="${srcPubnubApi.link}/com/pubnub/api"/>
109
<property name="sources_pubnub_logging" value="srcLogging/com/pubnub/api"/>
@@ -23,7 +22,6 @@
2322
<pathelement location="libs/junit-4.11.jar"/>
2423
<pathelement location="libs/hamcrest-all-1.3.jar" />
2524
<pathelement location="libs/commons-cli-1.2.jar"/>
26-
<pathelement location="jars/Pubnub-UnitTests-${VERSION}.jar"/>
2725
</path>
2826
<target name="build-all" depends="clean, debug-build, clean, build" />
2927
<target name="deploy-all" depends="clean, push_to_maven_central, clean, push_debug_to_maven_central" />
@@ -41,16 +39,6 @@
4139
<include name="**/*.java"/>
4240
</replace>
4341
</target>
44-
<target name="test" >
45-
<junit haltonfailure="yes" printsummary="yes" showoutput="true" >
46-
<classpath refid="PubnubApi.classpath" />
47-
<classpath refid="PubnubTests.classpath" />
48-
<formatter type="plain" usefile="false" />
49-
<batchtest>
50-
<zipfileset src="jars/${pubnub_unittests_jar_file_name}" includes="**/PubnubTest.class" />
51-
</batchtest>
52-
</junit>
53-
</target>
5442
<target name="init">
5543
<mkdir dir="bin"/>
5644
<copy includeemptydirs="false" todir="bin">
@@ -86,7 +74,7 @@
8674
<antcall target="unsetDebugTrue" />
8775
</target>
8876

89-
<target depends="create-jar, create-test-jar, create-examples-jar, create-demo-console-jar, create-push-test-jar, create-presence-test-jar, clean_bin, doc" name="build-jar"/>
77+
<target depends="create-jar, create-examples-jar, create-demo-console-jar, create-push-test-jar, create-presence-test-jar, clean_bin, doc" name="build-jar"/>
9078
<target depends="build-project" name="create-jar">
9179
<jar destfile="${jar_name}"
9280
basedir="bin"
@@ -95,13 +83,6 @@
9583
/>
9684
</target>
9785

98-
<target depends="build-project" name="create-test-jar">
99-
<jar destfile="jars/${pubnub_unittests_jar_file_name}"
100-
basedir="bin"
101-
includes="**/*Test*.class"
102-
/>
103-
</target>
104-
10586
<target depends="init" name="build-project">
10687
<echo message="${ant.project.name}: ${ant.file}"/>
10788
<replace dir="${srcPubnubApi.link}" token='static String VERSION = ""' value='static String VERSION = "${VERSION}"' >
@@ -112,7 +93,6 @@
11293
<src path="src"/>
11394
<src path="src1"/>
11495
<src path="srcLogging"/>
115-
<src path="srcTest"/>
11696
<src path="srcCrypto"/>
11797
<src path="examples/src"/>
11898
<classpath refid="PubnubApi.classpath"/>

java/pom.xml

Lines changed: 140 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,87 @@
11
<?xml version="1.0"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
45

5-
<groupId>com.pubnub</groupId>
6-
<artifactId>pubnub</artifactId>
7-
<version>3.7.3</version>
6+
<groupId>com.pubnub</groupId>
7+
<artifactId>pubnub</artifactId>
8+
<version>3.7.3</version>
89

9-
<packaging>jar</packaging>
10-
<name>pubnub</name>
11-
<description>PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter second!</description>
12-
<url>https://github.com/pubnub/java</url>
13-
<licenses>
14-
<license>
15-
<url>https://github.com/pubnub/pubnub-api/blob/master/LICENSE</url>
16-
<distribution>repo</distribution>
17-
</license>
18-
</licenses>
19-
<scm>
10+
<packaging>jar</packaging>
11+
<name>pubnub</name>
12+
<description>PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of
13+
broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter
14+
second!
15+
</description>
2016
<url>https://github.com/pubnub/java</url>
21-
<connection>scm:git:git://github.com/pubnub/java.git</connection>
22-
</scm>
23-
<developers>
24-
<developer>
25-
<id>pubnub</id>
26-
<name>Pubnub Inc.</name>
27-
<email>support@pubnub.com</email>
28-
<url>http://www.pubnub.com</url>
29-
</developer>
30-
</developers>
31-
17+
<licenses>
18+
<license>
19+
<url>https://github.com/pubnub/pubnub-api/blob/master/LICENSE</url>
20+
<distribution>repo</distribution>
21+
</license>
22+
</licenses>
23+
<scm>
24+
<url>https://github.com/pubnub/java</url>
25+
<connection>scm:git:git://github.com/pubnub/java.git</connection>
26+
</scm>
27+
<developers>
28+
<developer>
29+
<id>pubnub</id>
30+
<name>Pubnub Inc.</name>
31+
<email>support@pubnub.com</email>
32+
<url>http://www.pubnub.com</url>
33+
</developer>
34+
</developers>
35+
<properties>
36+
<powermock.version>1.6.2</powermock.version>
37+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38+
</properties>
39+
<build>
40+
<sourceDirectory>${project.basedir}/src</sourceDirectory>
41+
<testSourceDirectory>${project.basedir}/srcTest</testSourceDirectory>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.apache.maven.plugins</groupId>
45+
<artifactId>maven-surefire-plugin</artifactId>
46+
<version>2.18.1</version>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.apache.maven.surefire</groupId>
50+
<artifactId>surefire-junit47</artifactId>
51+
<version>2.18.1</version>
52+
</dependency>
53+
</dependencies>
54+
<configuration>
55+
<includes>
56+
<include>com/pubnub/api/**/*Test.java</include>
57+
</includes>
58+
</configuration>
59+
</plugin>
60+
<plugin>
61+
<groupId>org.codehaus.mojo</groupId>
62+
<artifactId>build-helper-maven-plugin</artifactId>
63+
<version>1.9.1</version>
64+
<executions>
65+
<execution>
66+
<id>add-source</id>
67+
<phase>generate-sources</phase>
68+
<goals>
69+
<goal>add-source</goal>
70+
</goals>
71+
<configuration>
72+
<sources>
73+
<source>src</source>
74+
<source>src1</source>
75+
<source>srcLogging</source>
76+
<source>srcCrypto</source>
77+
<source>srcPubnubApi</source>
78+
</sources>
79+
</configuration>
80+
</execution>
81+
</executions>
82+
</plugin>
83+
</plugins>
84+
</build>
3285
<dependencies>
3386
<dependency>
3487
<groupId>org.json</groupId>
@@ -45,5 +98,65 @@
4598
<artifactId>bcprov-jdk16</artifactId>
4699
<version>1.46</version>
47100
</dependency>
101+
<dependency>
102+
<groupId>junit</groupId>
103+
<artifactId>junit</artifactId>
104+
<version>4.12</version>
105+
<scope>test</scope>
106+
</dependency>
107+
<dependency>
108+
<groupId>org.hamcrest</groupId>
109+
<artifactId>hamcrest-all</artifactId>
110+
<version>1.3</version>
111+
<scope>test</scope>
112+
</dependency>
113+
<dependency>
114+
<groupId>org.mockito</groupId>
115+
<artifactId>mockito-all</artifactId>
116+
<version>1.10.19</version>
117+
<scope>test</scope>
118+
</dependency>
119+
<dependency>
120+
<groupId>org.powermock</groupId>
121+
<artifactId>powermock-api-mockito</artifactId>
122+
<version>${powermock.version}</version>
123+
<scope>test</scope>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.powermock</groupId>
127+
<artifactId>powermock-core</artifactId>
128+
<version>${powermock.version}</version>
129+
<scope>test</scope>
130+
</dependency>
131+
<dependency>
132+
<groupId>org.powermock</groupId>
133+
<artifactId>powermock-module-junit4</artifactId>
134+
<version>${powermock.version}</version>
135+
<scope>test</scope>
136+
</dependency>
137+
<dependency>
138+
<groupId>org.powermock</groupId>
139+
<artifactId>powermock-module-junit4-common</artifactId>
140+
<version>${powermock.version}</version>
141+
<scope>test</scope>
142+
</dependency>
143+
<dependency>
144+
<groupId>org.powermock</groupId>
145+
<artifactId>powermock-module-test-mockito-junit4-agent</artifactId>
146+
<version>${powermock.version}</version>
147+
<scope>test</scope>
148+
</dependency>
149+
<dependency>
150+
<groupId>org.powermock</groupId>
151+
<artifactId>powermock-module-junit4-rule</artifactId>
152+
<version>${powermock.version}</version>
153+
<scope>test</scope>
154+
</dependency>
155+
<dependency>
156+
<groupId>org.powermock</groupId>
157+
<artifactId>powermock-classloading-xstream</artifactId>
158+
<version>${powermock.version}</version>
159+
<scope>test</scope>
160+
</dependency>
48161
</dependencies>
49162
</project>

java/srcPubnubApi/com/pubnub/api/PubnubCore.java

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ abstract class PubnubCore {
4747
private volatile String _timetoken = "0";
4848
private volatile String _saved_timetoken = "0";
4949

50-
private String PRESENCE_SUFFIX = "-pnpres";
50+
protected static String PRESENCE_SUFFIX = "-pnpres";
51+
protected static String WILDCARD_SUFFIX = "*";
52+
protected static String WILDCARD_PRESENCE_SUFFIX = WILDCARD_SUFFIX + PRESENCE_SUFFIX;
5153
protected static String VERSION = "";
5254
private Random generator = new Random();
5355

@@ -195,7 +197,7 @@ public void handleError(HttpRequest hreq, PubnubError error) {
195197
* Presence Expiry timeout in seconds
196198
*/
197199
public void setPnExpires(int pnexpires, Callback callback) {
198-
setHeartbeat(pnexpires,callback);
200+
setHeartbeat(pnexpires, callback);
199201
}
200202

201203
/**
@@ -2315,12 +2317,32 @@ private void _subscribe(Hashtable args) {
23152317

23162318
for (int i = 0; i < channelList.length; i++) {
23172319
String channel = channelList[i];
2318-
SubscriptionItem channelObj = (SubscriptionItem) channelSubscriptions.getItem(channel);
23192320

2320-
if (channelObj == null) {
2321-
SubscriptionItem ch = new SubscriptionItem(channel, callback);
2321+
if (channel.endsWith(WILDCARD_SUFFIX + PRESENCE_SUFFIX)) {
2322+
String messagesChannel = channel.substring(0, channel.indexOf(PRESENCE_SUFFIX));
23222323

2323-
channelSubscriptions.addItem(ch);
2324+
SubscriptionItem wildcardMessagesObj = (SubscriptionItem) channelSubscriptions.getItem(messagesChannel);
2325+
SubscriptionItem wildcardPresenceObj = (SubscriptionItem) channelSubscriptions.getItem(channel);
2326+
2327+
if (wildcardMessagesObj == null) {
2328+
SubscriptionItem ch = new SubscriptionItem(messagesChannel, callback);
2329+
2330+
channelSubscriptions.addItem(ch);
2331+
}
2332+
2333+
if (wildcardPresenceObj == null) {
2334+
SubscriptionItem pr = new SubscriptionItem(channel, callback);
2335+
2336+
channelSubscriptions.addItem(pr);
2337+
}
2338+
} else {
2339+
SubscriptionItem channelObj = (SubscriptionItem) channelSubscriptions.getItem(channel);
2340+
2341+
if (channelObj == null) {
2342+
SubscriptionItem ch = new SubscriptionItem(channel, callback);
2343+
2344+
channelSubscriptions.addItem(ch);
2345+
}
23242346
}
23252347
}
23262348

@@ -2357,9 +2379,9 @@ private boolean isWorkerDead(HttpRequest hreq) {
23572379
return (hreq == null || hreq.getWorker() == null)?false:hreq.getWorker()._die;
23582380
}
23592381
private void _subscribe_base(boolean fresh, boolean dar, Worker worker) {
2360-
String channelString = channelSubscriptions.getItemString();
2382+
String channelString = channelSubscriptions.getItemString(WILDCARD_PRESENCE_SUFFIX);
23612383
String groupString = channelGroupSubscriptions.getItemString();
2362-
String[] channelsArray = channelSubscriptions.getItemNames();
2384+
String[] channelsArray = channelSubscriptions.getItemNames(WILDCARD_PRESENCE_SUFFIX);
23632385
String[] groupsArray = channelGroupSubscriptions.getItemNames();
23642386

23652387
if (channelsArray.length <= 0 && groupsArray.length <= 0) {
@@ -2444,26 +2466,8 @@ public void handleResponse(HttpRequest hreq, String response) {
24442466
String[] _channels = PubnubUtil.splitString(jsa.getString(3), ",");
24452467

24462468
for (int i = 0; i < _channels.length; i++) {
2447-
String _groupName = _groups[i];
2448-
String _channelName = _channels[i];
2449-
Object message = messages.get(i);
2450-
2451-
SubscriptionItem _group = channelGroupSubscriptions.getItem(_groups[i]);
2452-
SubscriptionItem _channel = channelSubscriptions.getItem(_groups[i]);
2453-
2454-
if (_groupName.equals(_channelName)
2455-
&& _channel != null
2456-
&& !isWorkerDead(hreq)
2457-
) {
2458-
invokeSubscribeCallback(_channelName, _channel.callback,
2459-
message, _timetoken, hreq);
2460-
} else if (!_groupName.equals(_channelName)
2461-
&& _group != null
2462-
&& !isWorkerDead(hreq)
2463-
) {
2464-
invokeSubscribeCallback(_channelName, _group.callback,
2465-
message, _timetoken, hreq);
2466-
}
2469+
handleFourElementsSubscribeResponse(_groups[i], _channels[i], messages.get(i),
2470+
_timetoken, hreq);
24672471
}
24682472
} else if(jsa.length() == 3) {
24692473
/*
@@ -2553,6 +2557,45 @@ public String getTimetoken() {
25532557
_request(hreq, subscribeManager, fresh);
25542558
}
25552559

2560+
/**
2561+
* Handle 4-elements success response
2562+
*
2563+
* @param thirdString element of JSON response
2564+
* @param fourthString element of JSON response
2565+
* @param message from JSON response
2566+
* @param timetoken from response
2567+
* @param hreq request
2568+
* @throws JSONException
2569+
*/
2570+
private void handleFourElementsSubscribeResponse(String thirdString, String fourthString, Object message,
2571+
String timetoken, HttpRequest hreq) throws JSONException {
2572+
2573+
SubscriptionItem thirdChannelGroup = channelGroupSubscriptions.getItem(thirdString);
2574+
SubscriptionItem thirdChannel = channelSubscriptions.getItem(thirdString);
2575+
SubscriptionItem fourthChannel = channelSubscriptions.getItem(fourthString);
2576+
2577+
if (isWorkerDead(hreq)) return;
2578+
2579+
if (thirdString.equals(fourthString) && fourthChannel != null) {
2580+
invokeSubscribeCallback(fourthString, fourthChannel.callback, message, timetoken, hreq);
2581+
} else if (thirdString.endsWith("*")) {
2582+
if (fourthChannel != null && fourthString.endsWith(PRESENCE_SUFFIX)) {
2583+
invokeSubscribeCallback(fourthString, fourthChannel.callback, message, timetoken, hreq);
2584+
} else if (thirdChannelGroup != null && !fourthString.endsWith(PRESENCE_SUFFIX)) {
2585+
invokeSubscribeCallback(fourthString, thirdChannelGroup.callback, message, timetoken, hreq);
2586+
} else if (thirdChannel != null && thirdString.endsWith(WILDCARD_SUFFIX)) {
2587+
invokeSubscribeCallback(fourthString, thirdChannel.callback, message, timetoken, hreq);
2588+
} else {
2589+
System.out.println("ERROR: Unable to handle wildcard response: " + message);
2590+
}
2591+
} else if (!thirdString.equals(fourthString) && thirdChannelGroup != null) {
2592+
invokeSubscribeCallback(fourthString, thirdChannelGroup.callback,
2593+
message, timetoken, hreq);
2594+
} else {
2595+
System.out.println("ERROR: Unable to handle response: " + message);
2596+
}
2597+
}
2598+
25562599
private void invokeSubscribeCallback(String channel, Callback callback, Object message, String timetoken,
25572600
HttpRequest hreq) throws JSONException {
25582601
if (CIPHER_KEY.length() > 0

0 commit comments

Comments
 (0)