
io.vertx.groovy.core.shareddata.SharedData.groovy Maven / Gradle / Ivy
/*
* 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