Hazelcast C++ Client
 All Classes Functions Variables Enumerations Enumerator Pages
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 
21 #include "hazelcast/client/map/impl/ClientMapProxyFactory.h"
22 #include "hazelcast/client/internal/nearcache/NearCacheManager.h"
23 #include "hazelcast/client/proxy/RingbufferImpl.h"
24 #include "hazelcast/client/IMap.h"
25 #include "hazelcast/client/MultiMap.h"
26 #include "hazelcast/client/IQueue.h"
27 #include "hazelcast/client/ISet.h"
28 #include "hazelcast/client/IList.h"
29 #include "hazelcast/client/ITopic.h"
30 #include "hazelcast/client/TransactionOptions.h"
31 #include "hazelcast/client/TransactionContext.h"
32 #include "hazelcast/client/Cluster.h"
33 #include "hazelcast/client/ClientConfig.h"
34 #include "hazelcast/client/ClientProperties.h"
35 #include "hazelcast/client/spi/InvocationService.h"
36 #include "hazelcast/client/spi/PartitionService.h"
37 #include "hazelcast/client/spi/ServerListenerService.h"
38 #include "hazelcast/client/spi/LifecycleService.h"
39 #include "hazelcast/client/spi/ProxyManager.h"
40 #include "hazelcast/client/Ringbuffer.h"
41 #include "hazelcast/client/ReliableTopic.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 
462  public:
469 
473  ~HazelcastClient();
474 
481  template<typename T>
482  T getDistributedObject(const std::string& name) {
483  T t(name, &(clientContext));
484  return t;
485  }
486 
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 
706  internal::nearcache::NearCacheManager &getNearCacheManager();
707 
708  serialization::pimpl::SerializationService &getSerializationService();
709  private:
710  boost::shared_ptr<spi::ClientProxy> getDistributedObjectForService(const std::string &serviceName,
711  const std::string &name,
712  spi::ClientProxyFactory &factory);
713 
714  ClientConfig clientConfig;
715  ClientProperties clientProperties;
716  spi::ClientContext clientContext;
717  spi::LifecycleService lifecycleService;
718  serialization::pimpl::SerializationService serializationService;
719  std::auto_ptr<connection::ConnectionManager> connectionManager;
720  internal::nearcache::NearCacheManager nearCacheManager;
721  spi::ClusterService clusterService;
722  spi::PartitionService partitionService;
723  spi::InvocationService invocationService;
724  spi::ServerListenerService serverListenerService;
725  Cluster cluster;
726  spi::ProxyManager proxyManager;
727 
728  HazelcastClient(const HazelcastClient& rhs);
729 
730  void operator=(const HazelcastClient& rhs);
731 
732  const std::string TOPIC_RB_PREFIX;
733  };
734 
735  }
736 }
737 
738 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
739 #pragma warning(pop)
740 #endif
741 
742 #endif /* HAZELCAST_CLIENT */
Contains the configuration for a Hazelcast transaction.
Definition: TransactionOptions.h:67
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)
Definition: HazelcastClient.h:498
Concurrent, distributed, observable and queryable map client.
Definition: IMap.h:66
ISemaphore is a backed-up distributed alternative to the java.util.concurrent.Semaphore.
Definition: ISemaphore.h:56
HazelcastClient configuration class.
Definition: ClientConfig.h:52
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:482