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 #ifndef HAZELCAST_TOPIC
19 #define HAZELCAST_TOPIC
20 
21 #include "hazelcast/client/proxy/ITopicImpl.h"
22 #include "hazelcast/client/topic/impl/TopicEventHandlerImpl.h"
23 #include <string>
24 
25 namespace hazelcast {
26  namespace client {
27 
40  template<typename E>
41  class ITopic : public proxy::ITopicImpl {
42  friend class HazelcastClient;
43 
44  public:
45 
51  void publish(const E& message) {
52  proxy::ITopicImpl::publish(toData<E>(message));
53  }
54 
79  template<typename L>
80  std::string addMessageListener(L& listener) {
81  impl::BaseEventHandler *topicEventHandler = new topic::impl::TopicEventHandlerImpl<E>(getName(),
82  context->getClusterService(),
83  context->getSerializationService(),
84  listener);
85  return proxy::ITopicImpl::addMessageListener(topicEventHandler);
86  }
87 
96  bool removeMessageListener(const std::string& registrationId) {
97  return proxy::ITopicImpl::removeMessageListener(registrationId);
98  };
99 
100  private:
101  ITopic(const std::string& instanceName, spi::ClientContext *context)
102  : proxy::ITopicImpl(instanceName, context) {
103  }
104  };
105  }
106 }
107 
108 #endif //HAZELCAST_TOPIC
109 
void publish(const E &message)
Publishes the message to all subscribers of this topic.
Definition: ITopic.h:51
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
Definition: ITopic.h:41
bool removeMessageListener(const std::string &registrationId)
Stops receiving messages for the given message listener.
Definition: ITopic.h:96
std::string addMessageListener(L &listener)
Subscribes to this topic.
Definition: ITopic.h:80
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:453