Skip to content

Commit 59069d9

Browse files
authored
Merge pull request #326 from Backendless/real-time
Real time
2 parents ea10bd0 + 822a7f5 commit 59069d9

File tree

65 files changed

+4171
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+4171
-246
lines changed

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'signing'
55

66

77
group 'com.backendless'
8-
version '4.5.0-snapshot'
8+
version '4.5.1-real-time-snapshot'
99
archivesBaseName='backendless'
1010

1111

@@ -230,5 +230,10 @@ dependencies {
230230
}
231231
compile( group: "weborb", name: "weborbclient", version: "5.1.0.212", changing: true)
232232

233+
compileOnly ('io.socket:socket.io-client:1.0.0') {
234+
// excluding org.json which is provided by Android
235+
exclude group: 'org.json', module: 'json'
236+
}
233237
}
238+
234239
apply plugin: 'java'
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Wed Mar 21 17:39:57 EET 2018
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
34
zipStoreBase=GRADLE_USER_HOME
45
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

src/com/backendless/Backendless.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import com.backendless.persistence.RealmSerializer;
3333
import com.backendless.persistence.local.UserIdStorageFactory;
3434
import com.backendless.persistence.local.UserTokenStorageFactory;
35+
import com.backendless.rt.RTService;
36+
import com.backendless.rt.RTServiceImpl;
3537
import weborb.ORBConstants;
3638
import weborb.config.ORBConfig;
3739
import weborb.util.ObjectFactories;
@@ -67,6 +69,7 @@ public final class Backendless
6769
public static final Counters Counters = com.backendless.Counters.getInstance();
6870
public static final CustomService CustomService = com.backendless.CustomService.getInstance();
6971
public static final Logging Logging = com.backendless.Logging.getInstance();
72+
public static final RTService RT = new RTServiceImpl();
7073
public static Media Media;
7174
private static boolean initialized;
7275

src/com/backendless/DataStoreFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.backendless.persistence.BackendlessSerializer;
2424
import com.backendless.persistence.DataQueryBuilder;
2525
import com.backendless.persistence.LoadRelationsQueryBuilder;
26+
import com.backendless.rt.data.EventHandler;
27+
import com.backendless.rt.data.EventHandlerFactory;
2628

2729
import java.util.ArrayList;
2830
import java.util.Collection;
@@ -32,11 +34,14 @@
3234
class DataStoreFactory
3335
{
3436
private static final List<String> emptyRelations = new ArrayList<String>();
37+
private final static EventHandlerFactory eventHandlerFactory = new EventHandlerFactory();
3538

3639
protected static <E> IDataStore<E> createDataStore( final Class<E> entityClass )
3740
{
41+
3842
return new IDataStore<E>()
3943
{
44+
private EventHandler<E> eventHandler = eventHandlerFactory.of( entityClass );
4045

4146
@Override
4247
public List<String> create( List<E> objects ) throws BackendlessException
@@ -538,6 +543,12 @@ public void deleteRelation( E parent, String relationColumnName, String whereCla
538543
Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, whereClause };
539544
Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deleteRelation", args, callback );
540545
}
546+
547+
@Override
548+
public EventHandler<E> rt()
549+
{
550+
return eventHandler;
551+
}
541552
};
542553
}
543554
}

src/com/backendless/IDataStore.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.backendless.exceptions.BackendlessException;
2323
import com.backendless.persistence.DataQueryBuilder;
2424
import com.backendless.persistence.LoadRelationsQueryBuilder;
25+
import com.backendless.rt.data.EventHandler;
2526

2627
import java.util.Collection;
2728
import java.util.List;
@@ -169,4 +170,6 @@ public interface IDataStore<E>
169170
int deleteRelation( E parent, String relationColumnName, String whereClause );
170171

171172
void deleteRelation( E parent, String relationColumnName, String whereClause, AsyncCallback<Integer> callback );
173+
174+
EventHandler<E> rt();
172175
}

src/com/backendless/Messaging.java

Lines changed: 7 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import com.backendless.messaging.PushBroadcastMask;
5252
import com.backendless.messaging.SubscriptionOptions;
5353
import com.backendless.push.GCMRegistrar;
54+
import com.backendless.rt.messaging.Channel;
55+
import com.backendless.rt.messaging.ChannelFactory;
5456
import weborb.types.Types;
5557

5658
import java.util.ArrayList;
@@ -69,6 +71,7 @@ public final class Messaging
6971
private final static String OS;
7072
private final static String OS_VERSION;
7173
private static final Messaging instance = new Messaging();
74+
private static final ChannelFactory chanelFactory = new ChannelFactory();
7275

7376
private Messaging()
7477
{
@@ -614,173 +617,14 @@ public void cancel( String messageId, AsyncCallback<MessageStatus> responder )
614617
}
615618
}
616619

617-
public Subscription subscribe( AsyncCallback<List<Message>> subscriptionResponder ) throws BackendlessException
620+
public Channel subscribe( )
618621
{
619-
return subscribe( DEFAULT_CHANNEL_NAME, subscriptionResponder, null, 0 );
622+
return subscribe( "default" );
620623
}
621624

622-
public Subscription subscribe( String channelName, AsyncCallback<List<Message>> subscriptionResponder,
623-
SubscriptionOptions subscriptionOptions,
624-
int pollingInterval ) throws BackendlessException
625+
public Channel subscribe( String channelName )
625626
{
626-
checkChannelName( channelName );
627-
628-
if( pollingInterval < 0 )
629-
throw new IllegalArgumentException( ExceptionMessage.WRONG_POLLING_INTERVAL );
630-
631-
String subscriptionId = subscribeForPollingAccess( channelName, subscriptionOptions );
632-
633-
Subscription subscription = new Subscription();
634-
subscription.setChannelName( channelName );
635-
subscription.setSubscriptionId( subscriptionId );
636-
637-
if( pollingInterval != 0 )
638-
subscription.setPollingInterval( pollingInterval );
639-
640-
subscription.onSubscribe( subscriptionResponder );
641-
642-
return subscription;
643-
}
644-
645-
private String subscribeForPollingAccess( String channelName,
646-
SubscriptionOptions subscriptionOptions ) throws BackendlessException
647-
{
648-
if( channelName == null )
649-
throw new IllegalArgumentException( ExceptionMessage.NULL_CHANNEL_NAME );
650-
651-
if( subscriptionOptions == null )
652-
subscriptionOptions = new SubscriptionOptions();
653-
654-
return Invoker.invokeSync( MESSAGING_MANAGER_SERVER_ALIAS, "subscribeForPollingAccess", new Object[] { channelName, subscriptionOptions } );
655-
}
656-
657-
public Subscription subscribe( String channelName,
658-
AsyncCallback<List<Message>> subscriptionResponder ) throws BackendlessException
659-
{
660-
return subscribe( channelName, subscriptionResponder, null, 0 );
661-
}
662-
663-
public Subscription subscribe( int pollingInterval,
664-
AsyncCallback<List<Message>> subscriptionResponder ) throws BackendlessException
665-
{
666-
return subscribe( DEFAULT_CHANNEL_NAME, subscriptionResponder, null, pollingInterval );
667-
}
668-
669-
public Subscription subscribe( String channelName, int pollingInterval,
670-
AsyncCallback<List<Message>> subscriptionResponder ) throws BackendlessException
671-
{
672-
return subscribe( channelName, subscriptionResponder, null, pollingInterval );
673-
}
674-
675-
public Subscription subscribe( AsyncCallback<List<Message>> subscriptionResponder,
676-
SubscriptionOptions subscriptionOptions ) throws BackendlessException
677-
{
678-
return subscribe( DEFAULT_CHANNEL_NAME, subscriptionResponder, subscriptionOptions, 0 );
679-
}
680-
681-
public Subscription subscribe( String channelName, AsyncCallback<List<Message>> subscriptionResponder,
682-
SubscriptionOptions subscriptionOptions ) throws BackendlessException
683-
{
684-
return subscribe( channelName, subscriptionResponder, subscriptionOptions, 0 );
685-
}
686-
687-
public void subscribe( AsyncCallback<List<Message>> subscriptionResponder, AsyncCallback<Subscription> responder )
688-
{
689-
subscribe( DEFAULT_CHANNEL_NAME, subscriptionResponder, null, 0, responder );
690-
}
691-
692-
public void subscribe( final String channelName, final AsyncCallback<List<Message>> subscriptionResponder,
693-
SubscriptionOptions subscriptionOptions, final int pollingInterval,
694-
final AsyncCallback<Subscription> responder )
695-
{
696-
try
697-
{
698-
checkChannelName( channelName );
699-
700-
if( pollingInterval < 0 )
701-
throw new IllegalArgumentException( ExceptionMessage.WRONG_POLLING_INTERVAL );
702-
703-
subscribeForPollingAccess( channelName, subscriptionOptions, new AsyncCallback<String>()
704-
{
705-
@Override
706-
public void handleResponse( String subscriptionId )
707-
{
708-
Subscription subscription = new Subscription();
709-
subscription.setChannelName( channelName );
710-
subscription.setSubscriptionId( subscriptionId );
711-
712-
if( pollingInterval != 0 )
713-
subscription.setPollingInterval( pollingInterval );
714-
715-
subscription.onSubscribe( subscriptionResponder );
716-
717-
if( responder != null )
718-
responder.handleResponse( subscription );
719-
}
720-
721-
@Override
722-
public void handleFault( BackendlessFault fault )
723-
{
724-
if( responder != null )
725-
responder.handleFault( fault );
726-
}
727-
} );
728-
}
729-
catch( Throwable e )
730-
{
731-
if( responder != null )
732-
responder.handleFault( new BackendlessFault( e ) );
733-
}
734-
}
735-
736-
private void subscribeForPollingAccess( String channelName, SubscriptionOptions subscriptionOptions,
737-
AsyncCallback<String> responder )
738-
{
739-
try
740-
{
741-
if( channelName == null )
742-
throw new IllegalArgumentException( ExceptionMessage.NULL_CHANNEL_NAME );
743-
744-
if( subscriptionOptions == null )
745-
subscriptionOptions = new SubscriptionOptions();
746-
747-
Invoker.invokeAsync( MESSAGING_MANAGER_SERVER_ALIAS, "subscribeForPollingAccess", new Object[] { channelName, subscriptionOptions }, responder );
748-
}
749-
catch( Throwable e )
750-
{
751-
if( responder != null )
752-
responder.handleFault( new BackendlessFault( e ) );
753-
}
754-
}
755-
756-
public void subscribe( String channelName, AsyncCallback<List<Message>> subscriptionResponder,
757-
AsyncCallback<Subscription> responder )
758-
{
759-
subscribe( channelName, subscriptionResponder, null, 0, responder );
760-
}
761-
762-
public void subscribe( int pollingInterval, AsyncCallback<List<Message>> subscriptionResponder,
763-
AsyncCallback<Subscription> responder )
764-
{
765-
subscribe( DEFAULT_CHANNEL_NAME, subscriptionResponder, null, pollingInterval, responder );
766-
}
767-
768-
public void subscribe( String channelName, int pollingInterval, AsyncCallback<List<Message>> subscriptionResponder,
769-
AsyncCallback<Subscription> responder )
770-
{
771-
subscribe( channelName, subscriptionResponder, null, pollingInterval, responder );
772-
}
773-
774-
public void subscribe( AsyncCallback<List<Message>> subscriptionResponder, SubscriptionOptions subscriptionOptions,
775-
AsyncCallback<Subscription> responder )
776-
{
777-
subscribe( DEFAULT_CHANNEL_NAME, subscriptionResponder, subscriptionOptions, 0, responder );
778-
}
779-
780-
public void subscribe( String channelName, AsyncCallback<List<Message>> subscriptionResponder,
781-
SubscriptionOptions subscriptionOptions, AsyncCallback<Subscription> responder )
782-
{
783-
subscribe( channelName, subscriptionResponder, subscriptionOptions, 0, responder );
627+
return chanelFactory.create( channelName );
784628
}
785629

786630
public List<Message> pollMessages( String channelName, String subscriptionId ) throws BackendlessException

src/com/backendless/UserService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.backendless.persistence.local.UserTokenStorageFactory;
3030
import com.backendless.property.AbstractProperty;
3131
import com.backendless.property.UserProperty;
32+
import com.backendless.rt.RTClientFactory;
3233
import com.facebook.CallbackManager;
3334
import weborb.types.Types;
3435

@@ -486,6 +487,7 @@ private void handleLogout()
486487
HeadersManager.getInstance().removeHeader( HeadersManager.HeadersEnum.USER_TOKEN_KEY );
487488
UserTokenStorageFactory.instance().getStorage().set( "" );
488489
UserIdStorageFactory.instance().getStorage().set( "" );
490+
RTClientFactory.get().userLoggedOut();
489491
}
490492

491493
public void logout( final AsyncCallback<Void> responder )
@@ -824,6 +826,8 @@ private void handleUserLogin( BackendlessUser invokeResult, boolean stayLoggedIn
824826
UserTokenStorageFactory.instance().getStorage().set( "" );
825827
UserIdStorageFactory.instance().getStorage().set( "" );
826828
}
829+
830+
RTClientFactory.get().userLoggedIn( userToken );
827831
}
828832

829833
private AsyncCallback<BackendlessUser> getUserLoginAsyncHandler(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.backendless.async.callback;
2+
3+
import com.backendless.exceptions.BackendlessFault;
4+
5+
public interface Fault extends Result<BackendlessFault>
6+
{
7+
@Override
8+
void handle( BackendlessFault fault );
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.backendless.async.callback;
2+
3+
public interface Result<T>
4+
{
5+
void handle(T result);
6+
}

src/com/backendless/exceptions/BackendlessException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public String toString()
118118
sb.append( "{ code: '" ).append( getCode() ).append( '\'' );
119119
sb.append( ", message: '" ).append( getMessage() ).append( '\'' );
120120
sb.append( ", extendedData: '").append( getExtendedData() ).append( '\'' );
121+
sb.append( ", detail: '" ).append( getDetail() ).append( '\'' );
121122
sb.append( " }" );
122123
return sb.toString();
123124
}

0 commit comments

Comments
 (0)