Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
ITopic.h
1 /*
2  * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 //
17 // Created by sancar koyunlu on 6/20/13.
18 
19 
20 
21 
22 #ifndef HAZELCAST_TOPIC
23 #define HAZELCAST_TOPIC
24 
25 #include "hazelcast/client/proxy/ITopicImpl.h"
26 #include "hazelcast/client/topic/TopicEventHandler.h"
27 #include <string>
28 
29 namespace hazelcast {
30  namespace client {
31 
44  template<typename E>
45  class ITopic : public proxy::ITopicImpl {
46  friend class HazelcastClient;
47 
48  public:
49 
55  void publish(const E& message) {
56  proxy::ITopicImpl::publish(toData<E>(message));
57  }
58 
83  template<typename L>
84  std::string addMessageListener(L& listener) {
85  topic::TopicEventHandler<E, L> *topicEventHandler = new topic::TopicEventHandler<E, L>(getName(), context->getClusterService(), context->getSerializationService(), listener);
86  return proxy::ITopicImpl::addMessageListener(topicEventHandler);
87  }
88 
97  bool removeMessageListener(const std::string& registrationId) {
98  return proxy::ITopicImpl::removeMessageListener(registrationId);
99  };
100 
101  private:
102  ITopic(const std::string& instanceName, spi::ClientContext *context)
103  : proxy::ITopicImpl(instanceName, context) {
104  }
105  };
106  }
107 }
108 
109 #endif //HAZELCAST_TOPIC
110 
void publish(const E &message)
Publishes the message to all subscribers of this topic.
Definition: ITopic.h:55
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
Definition: ITopic.h:45
bool removeMessageListener(const std::string &registrationId)
Stops receiving messages for the given message listener.
Definition: ITopic.h:97
std::string addMessageListener(L &listener)
Subscribes to this topic.
Definition: ITopic.h:84
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:412