Hazelcast C++ Client
HazelcastClient.h
1 /*
2  * Copyright (c) 2008-2017, 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 #ifndef HAZELCAST_CLIENT
17 #define HAZELCAST_CLIENT
18 
19 #include <memory>
20 #include "hazelcast/client/map/impl/ClientMapProxyFactory.h"
21 #include "hazelcast/client/internal/nearcache/NearCacheManager.h"
22 #include "hazelcast/client/proxy/RingbufferImpl.h"
23 #include "hazelcast/client/IMap.h"
24 #include "hazelcast/client/MultiMap.h"
25 #include "hazelcast/client/IQueue.h"
26 #include "hazelcast/client/ISet.h"
27 #include "hazelcast/client/IList.h"
28 #include "hazelcast/client/ITopic.h"
29 #include "hazelcast/client/TransactionOptions.h"
30 #include "hazelcast/client/TransactionContext.h"
31 #include "hazelcast/client/Cluster.h"
32 #include "hazelcast/client/ClientConfig.h"
33 #include "hazelcast/client/ClientProperties.h"
34 #include "hazelcast/client/spi/InvocationService.h"
35 #include "hazelcast/client/spi/PartitionService.h"
36 #include "hazelcast/client/spi/ServerListenerService.h"
37 #include "hazelcast/client/spi/LifecycleService.h"
38 #include "hazelcast/client/spi/ProxyManager.h"
39 #include "hazelcast/client/Ringbuffer.h"
40 #include "hazelcast/client/ReliableTopic.h"
41 #include "hazelcast/client/mixedtype/HazelcastClient.h"
42 
43 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
44 #pragma warning(push)
45 #pragma warning(disable: 4251) //for dll export
46 #endif
47 
48 namespace hazelcast {
49  namespace client {
408  namespace connection {
409  class ConnectionManager;
410  }
411 
412  namespace serialization {
413  namespace pimpl {
414  class SerializationService;
415  }
416  }
417  namespace spi {
418  class ClientContext;
419 
420  class InvocationService;
421 
422  class ClusterService;
423 
424  class PartitionService;
425 
426  class LifecycleService;
427 
428  class ServerListenerService;
429 
430  class ClientProxyFactory;
431 
432  }
433 
434  class ClientConfig;
435 
436  class IdGenerator;
437 
438  class IAtomicLong;
439 
440  class ICountDownLatch;
441 
442  class ISemaphore;
443 
444  class ILock;
445 
446  class TransactionContext;
447 
448  class TransactionOptions;
449 
450  class Cluster;
451 
459  class HAZELCAST_API HazelcastClient {
460  friend class spi::ClientContext;
461  friend class mixedtype::impl::HazelcastClientImpl;
462 
463  public:
469  HazelcastClient(ClientConfig &config);
470 
474  ~HazelcastClient();
475 
482  template<typename T>
483  T getDistributedObject(const std::string& name) {
484  T t(name, &(clientContext));
485  return t;
486  }
487 
497  template<typename K, typename V>
498  IMap<K, V> getMap(const std::string &name) {
499  map::impl::ClientMapProxyFactory<K, V> factory(&clientContext);
500  boost::shared_ptr<spi::ClientProxy> proxy =
501  getDistributedObjectForService(IMap<K, V>::SERVICE_NAME, name, factory);
502 
503  return IMap<K, V>(proxy);
504  }
505 
512  template<typename K, typename V>
513  MultiMap<K, V> getMultiMap(const std::string& name) {
514  return getDistributedObject<MultiMap<K, V> >(name);
515  }
516 
523  template<typename E>
524  IQueue<E> getQueue(const std::string& name) {
525  return getDistributedObject<IQueue<E> >(name);
526  }
527 
536  template<typename E>
537  ISet<E> getSet(const std::string& name) {
538  return getDistributedObject<ISet<E> >(name);
539  }
540 
548  template<typename E>
549  IList<E> getList(const std::string& name) {
550  return getDistributedObject<IList<E> >(name);
551  }
552 
559  template<typename E>
560  ITopic<E> getTopic(const std::string& name) {
561  return getDistributedObject<ITopic<E> >(name);
562  };
563 
570  template<typename E>
571  boost::shared_ptr<ReliableTopic<E> > getReliableTopic(const std::string& name) {
572  boost::shared_ptr<Ringbuffer<topic::impl::reliable::ReliableTopicMessage> > rb =
573  getRingbuffer<topic::impl::reliable::ReliableTopicMessage>(TOPIC_RB_PREFIX + name);
574  return boost::shared_ptr<ReliableTopic<E> >(new ReliableTopic<E>(name, &clientContext, rb));
575  }
576 
585  IdGenerator getIdGenerator(const std::string& name);
586 
594  IAtomicLong getIAtomicLong(const std::string& name);
595 
604  ICountDownLatch getICountDownLatch(const std::string& name);
605 
630  ILock getILock(const std::string& name);
631 
638  template <typename E>
639  boost::shared_ptr<Ringbuffer<E> > getRingbuffer(const std::string& name) {
640  return boost::shared_ptr<Ringbuffer<E> >(new proxy::RingbufferImpl<E>(name, &clientContext));
641  }
642 
650  ISemaphore getISemaphore(const std::string& name);
651 
656  ClientConfig& getClientConfig();
657 
663  TransactionContext newTransactionContext();
664 
671  TransactionContext newTransactionContext(const TransactionOptions& options);
672 
680  Cluster& getCluster();
681 
692  void addLifecycleListener(LifecycleListener *lifecycleListener);
693 
699  bool removeLifecycleListener(LifecycleListener *lifecycleListener);
700 
704  void shutdown();
705 
711  mixedtype::HazelcastClient &toMixedType() const;
712 
713  internal::nearcache::NearCacheManager &getNearCacheManager();
714 
715  serialization::pimpl::SerializationService &getSerializationService();
716  private:
717  boost::shared_ptr<spi::ClientProxy> getDistributedObjectForService(const std::string &serviceName,
718  const std::string &name,
719  spi::ClientProxyFactory &factory);
720 
721  ClientConfig clientConfig;
722  ClientProperties clientProperties;
723  util::CountDownLatch shutdownLatch;
724  spi::ClientContext clientContext;
725  serialization::pimpl::SerializationService serializationService;
726  std::auto_ptr<connection::ConnectionManager> connectionManager;
727  internal::nearcache::NearCacheManager nearCacheManager;
728  spi::ClusterService clusterService;
729  spi::PartitionService partitionService;
730  spi::InvocationService invocationService;
731  spi::ServerListenerService serverListenerService;
732  Cluster cluster;
733  spi::LifecycleService lifecycleService;
734  spi::ProxyManager proxyManager;
735  std::auto_ptr<mixedtype::HazelcastClient> mixedTypeSupportAdaptor;
736 
737  HazelcastClient(const HazelcastClient& rhs);
738 
739  void operator=(const HazelcastClient& rhs);
740 
741  const std::string TOPIC_RB_PREFIX;
742  };
743 
744  }
745 }
746 
747 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
748 #pragma warning(pop)
749 #endif
750 
751 #endif /* HAZELCAST_CLIENT */
Contains the configuration for a Hazelcast transaction.
Definition: TransactionOptions.h:67
Definition: HazelcastClient.h:39
Concurrent, blocking, distributed, observable, client queue.
Definition: IQueue.h:38
ITopic< E > getTopic(const std::string &name)
Returns the distributed topic instance with the specified name and entry type E.
Definition: HazelcastClient.h:560
Cluster-wide unique id generator.
Definition: IdGenerator.h:42
IQueue< E > getQueue(const std::string &name)
Returns the distributed queue instance with the specified name and entry type E.
Definition: HazelcastClient.h:524
IAtomicLong is a distributed atomic long implementation.
Definition: IAtomicLong.h:38
ICountDownLatch is a backed-up distributed alternative to the java.util.concurrent.CountDownLatch java.util.concurrent.CountDownLatch.
Definition: ICountDownLatch.h:62
MultiMap< K, V > getMultiMap(const std::string &name)
Returns the distributed multimap instance with the specified name.
Definition: HazelcastClient.h:513
boost::shared_ptr< ReliableTopic< E > > getReliableTopic(const std::string &name)
Returns the distributed topic instance with the specified name and entry type E.
Definition: HazelcastClient.h:571
IList< E > getList(const std::string &name)
Returns the distributed list instance with the specified name.
Definition: HazelcastClient.h:549
A specialized distributed map client whose keys can be associated with multiple values.
Definition: MultiMap.h:41
Re-entrant Lock, Distributed client implementation of Lock.
Definition: ILock.h:40
Client Properties is an internal class.
Definition: ClientProperties.h:71
Concurrent, distributed , client implementation of std::list.
Definition: IList.h:42
Concurrent, distributed client implementation of std::unordered_set.
Definition: ISet.h:36
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
Definition: ITopic.h:41
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
Definition: ReliableTopic.h:45
boost::shared_ptr< Ringbuffer< E > > getRingbuffer(const std::string &name)
Returns the distributed Ringbuffer instance with the specified name.
Definition: HazelcastClient.h:639
Hazelcast cluster interface.
Definition: Cluster.h:38
NearCacheManager is the contract point to manage all existing NearCache instances.
Definition: NearCacheManager.h:40
ISet< E > getSet(const std::string &name)
Returns the distributed set instance with the specified name and entry type E.
Definition: HazelcastClient.h:537
Listener object for listening lifecycle events of hazelcast instance.
Definition: LifecycleListener.h:44
IMap< K, V > getMap(const std::string &name)
Returns the distributed map instance with the specified name.
Definition: HazelcastClient.h:498
Concurrent, distributed, observable and queryable map client.
Definition: IMap.h:66
Definition: MapEntryView.h:32
ISemaphore is a backed-up distributed alternative to the java.util.concurrent.Semaphore.
Definition: ISemaphore.h:56
HazelcastClient configuration class.
Definition: ClientConfig.h:51
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:459
Provides a context to do transactional operations; so beginning/committing transactions, but also retrieving transactional data-structures like the TransactionalMap.
Definition: TransactionContext.h:52
T getDistributedObject(const std::string &name)
Definition: HazelcastClient.h:483