-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/org/wso2/carbon/connector/operations/GetObjectIdleTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. 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 org.wso2.carbon.connector.operations; | ||
|
||
import org.apache.synapse.MessageContext; | ||
import org.wso2.carbon.connector.core.AbstractConnector; | ||
import org.wso2.carbon.connector.core.ConnectException; | ||
import org.wso2.carbon.connector.util.RedisConstants; | ||
import redis.clients.jedis.Jedis; | ||
|
||
public class GetObjectIdleTime extends AbstractConnector { | ||
|
||
@Override | ||
public void connect(MessageContext messageContext) throws ConnectException { | ||
RedisServer serverObj = null; | ||
try { | ||
serverObj = new RedisServer(messageContext); | ||
String key = messageContext.getProperty(RedisConstants.KEY).toString(); | ||
String response; | ||
Jedis jedis = null; | ||
try { | ||
jedis = serverObj.getJedis(); | ||
response = jedis.objectIdletime(key.getBytes()).toString(); | ||
} finally { | ||
if (jedis != null) { | ||
jedis.close(); | ||
} | ||
} | ||
|
||
|
||
if (response != null) { | ||
messageContext.setProperty(RedisConstants.RESULT_OF_IDLE, response); | ||
} else { | ||
handleException("Redis server throw null response", messageContext); | ||
} | ||
} catch (Exception e) { | ||
handleException("Error while connecting the server or calling the redis method", e, messageContext); | ||
} finally { | ||
if (serverObj != null) { | ||
serverObj.close(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
WSO2 Inc. 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. | ||
--> | ||
|
||
<template xmlns="http://ws.apache.org/ns/synapse" name="getObjectIdleTime"> | ||
<parameter name="redisKey" description="the key "/> | ||
<sequence> | ||
<property name="redisKey" expression="$func:redisKey"/> | ||
<class name="org.wso2.carbon.connector.operations.GetObjectIdleTime"/> | ||
<property name="redisResponse" expression="$ctx:result_of_idle"/> | ||
<payloadFactory media-type="json"> | ||
<format> | ||
{ | ||
"output":"$1" | ||
} | ||
</format> | ||
<args> | ||
<arg evaluator="xml" expression="$ctx:redisResponse" literal="true"/> | ||
</args> | ||
</payloadFactory> | ||
</sequence> | ||
</template> |