All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.groovy.core.shareddata.SharedData.groovy Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR3
Show newest version
/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.vertx.groovy.core.shareddata;
import groovy.transform.CompileStatic
import io.vertx.lang.groovy.InternalHelper
import io.vertx.core.json.JsonObject
import io.vertx.core.AsyncResult
import io.vertx.core.Handler
/**
 * Shared data allows you to share data safely between different parts of your application in a safe way.
 * 

* Shared data provides: *

    *
  • Cluster wide maps which can be accessed from any node of the cluster
  • *
  • Cluster wide locks which can be used to give exclusive access to resources across the cluster
  • *
  • Cluster wide counters used to maintain counts consistently across the cluster
  • *
  • Local maps for sharing data safely in the same Vert.x instance
  • *
*

* Please see the documentation for more information. */ @CompileStatic public class SharedData { private final def io.vertx.core.shareddata.SharedData delegate; public SharedData(Object delegate) { this.delegate = (io.vertx.core.shareddata.SharedData) delegate; } public Object getDelegate() { return delegate; } /** * Get the cluster wide map with the specified name. The map is accessible to all nodes in the cluster and data * put into the map from any node is visible to to any other node. * @param name the name of the map * @param resultHandler the map will be returned asynchronously in this handler */ public void getClusterWideMap(String name, Handler>> resultHandler) { this.delegate.getClusterWideMap(name, new Handler>>() { public void handle(AsyncResult> event) { AsyncResult> f if (event.succeeded()) { f = InternalHelper.>result(new AsyncMap(event.result())) } else { f = InternalHelper.>failure(event.cause()) } resultHandler.handle(f) } }); } /** * Get a cluster wide lock with the specified name. The lock will be passed to the handler when it is available. * @param name the name of the lock * @param resultHandler the handler */ public void getLock(String name, Handler> resultHandler) { this.delegate.getLock(name, new Handler>() { public void handle(AsyncResult event) { AsyncResult f if (event.succeeded()) { f = InternalHelper.result(new Lock(event.result())) } else { f = InternalHelper.failure(event.cause()) } resultHandler.handle(f) } }); } /** * Like {@link io.vertx.groovy.core.shareddata.SharedData#getLock} but specifying a timeout. If the lock is not obtained within the timeout * a failure will be sent to the handler * @param name the name of the lock * @param timeout the timeout in ms * @param resultHandler the handler */ public void getLockWithTimeout(String name, long timeout, Handler> resultHandler) { this.delegate.getLockWithTimeout(name, timeout, new Handler>() { public void handle(AsyncResult event) { AsyncResult f if (event.succeeded()) { f = InternalHelper.result(new Lock(event.result())) } else { f = InternalHelper.failure(event.cause()) } resultHandler.handle(f) } }); } /** * Get a cluster wide counter. The counter will be passed to the handler. * @param name the name of the counter. * @param resultHandler the handler */ public void getCounter(String name, Handler> resultHandler) { this.delegate.getCounter(name, new Handler>() { public void handle(AsyncResult event) { AsyncResult f if (event.succeeded()) { f = InternalHelper.result(new Counter(event.result())) } else { f = InternalHelper.failure(event.cause()) } resultHandler.handle(f) } }); } /** * Return a LocalMap with the specific name. * @param name the name of the map * @return the msp */ public LocalMap getLocalMap(String name) { def ret= InternalHelper.safeCreate(this.delegate.getLocalMap(name), io.vertx.groovy.core.shareddata.LocalMap.class); return ret; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy