5151import com .backendless .messaging .PushBroadcastMask ;
5252import com .backendless .messaging .SubscriptionOptions ;
5353import com .backendless .push .GCMRegistrar ;
54+ import com .backendless .rt .messaging .Channel ;
55+ import com .backendless .rt .messaging .ChannelFactory ;
5456import weborb .types .Types ;
5557
5658import 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
0 commit comments