Search in sources :

Example 86 with UnitResponse

use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.

the class DistributedLock method unlock.

public boolean unlock(CacheConfigBean cacheConfigBean) {
    final long applyTime = System.currentTimeMillis();
    if (lockKey == null)
        return false;
    UnitResponse unitResponseObject = SyncXian.call("cache", "distributedUnLock", new JSONObject() {

        {
            put("cacheConfig", cacheConfigBean);
            put("key", lockKey);
            put("value", value);
        }
    });
    if (!EnvUtil.getEnv().equals(EnvUtil.PRODUCTION)) {
        final long receiveTime = System.currentTimeMillis();
        final String result = unitResponseObject.succeeded() ? "成功" : "失败";
        LOG.info(String.format("锁编号: %s, key: %s, lockKey: %s, value: %s, 分布式解锁, %s, 影响数量: %s, 耗时: %s 毫秒", autoIncrement, key, lockKey, value, result, unitResponseObject.getData(), (receiveTime - applyTime)));
    }
    if (!unitResponseObject.succeeded()) {
        LOG.error(unitResponseObject);
        return false;
    }
    return true;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UnitResponse(info.xiancloud.core.message.UnitResponse)

Example 87 with UnitResponse

use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.

the class CacheSystemUtil method jedisPoolAdd.

/**
 * Add a cache datasource into the cache pool.
 *
 * @param cacheConfigBean the datasource configuration.
 */
public static void jedisPoolAdd(CacheConfigBean cacheConfigBean) {
    UnitResponse unitResponseObject = SyncXian.call(CacheService.CACHE_SERVICE, "jedisPoolAdd", new JSONObject() {

        {
            put("host", cacheConfigBean.getHost());
            put("port", cacheConfigBean.getPort());
            put("password", cacheConfigBean.getPassword());
            put("dbIndex", cacheConfigBean.getDbIndex());
        }
    });
    unitResponseObject.throwExceptionIfNotSuccess();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UnitResponse(info.xiancloud.core.message.UnitResponse)

Example 88 with UnitResponse

use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.

the class CloudFile method save.

/**
 * @param path  文件相对路径
 * @param data  文件内容
 * @param async 是否异步执行,如果不清楚,请使用{@linkplain CloudFile#save(String, String)}
 */
public static void save(String path, String data, boolean async) {
    Map map = new HashMap<String, Object>() {

        {
            put("path", path);
            put("data", data);
        }
    };
    if (async) {
        Xian.call("cosService", "cosWrite", map, new NotifyHandler() {

            @Override
            protected void handle(UnitResponse unitResponse) {
                LOG.info(unitResponse);
            }
        });
    } else {
        SyncXian.call("cosService", "cosWrite", map);
    }
}
Also used : HashMap(java.util.HashMap) UnitResponse(info.xiancloud.core.message.UnitResponse) NotifyHandler(info.xiancloud.core.NotifyHandler) Map(java.util.Map) HashMap(java.util.HashMap)

Example 89 with UnitResponse

use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.

the class AbstractDiyMonitorUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    JSONArray responseMonitor = new JSONArray();
    String title = title();
    if (title == null || "".equals(title.trim()))
        // todo why success with empty array? not failure or exception?
        return UnitResponse.success(responseMonitor);
    Object monitor = execute0();
    if (monitor != null) {
        if (monitor instanceof UnitResponse)
            padding(responseMonitor, ((UnitResponse) monitor).getData());
        else
            padding(responseMonitor, monitor);
    }
    return UnitResponse.success(responseMonitor);
}
Also used : UnitResponse(info.xiancloud.core.message.UnitResponse) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject)

Example 90 with UnitResponse

use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.

the class CacheMapUtil method exists.

@Deprecated
public static boolean exists(CacheConfigBean cacheConfigBean, String key, String field) {
    UnitResponse unitResponseObject = SyncXian.call(CacheService.CACHE_SERVICE, "cacheMapExists", new JSONObject() {

        {
            put("cacheConfig", cacheConfigBean);
            put("key", key);
            put("field", field);
        }
    });
    unitResponseObject.throwExceptionIfNotSuccess();
    return (boolean) unitResponseObject.getData();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UnitResponse(info.xiancloud.core.message.UnitResponse)

Aggregations

UnitResponse (info.xiancloud.core.message.UnitResponse)106 JSONObject (com.alibaba.fastjson.JSONObject)74 HashMap (java.util.HashMap)22 UnitRequest (info.xiancloud.core.message.UnitRequest)17 NotifyHandler (info.xiancloud.core.NotifyHandler)16 JSONArray (com.alibaba.fastjson.JSONArray)9 Unit (info.xiancloud.core.Unit)6 UnitMeta (info.xiancloud.core.UnitMeta)6 CacheGroup (info.xiancloud.cache.service.CacheGroup)5 Group (info.xiancloud.core.Group)5 Input (info.xiancloud.core.Input)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Redis (info.xiancloud.cache.redis.Redis)4 CacheConfigBean (info.xiancloud.core.support.cache.CacheConfigBean)4 ThreadPoolManager (info.xiancloud.core.thread_pool.ThreadPoolManager)3 LOG (info.xiancloud.core.util.LOG)3 Set (java.util.Set)3 Test (org.junit.Test)3 MessageType (info.xiancloud.core.distribution.MessageType)2 UnitUndefinedException (info.xiancloud.core.distribution.exception.UnitUndefinedException)2