Skip to content

Commit

Permalink
Merge pull request #37 from malakaganga/fix_get_Object_IdleTime
Browse files Browse the repository at this point in the history
Add OBJECT IDLETIME operation
  • Loading branch information
malakaganga authored Mar 24, 2023
2 parents 744b71d + f0e64cf commit 277afb8
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>org.wso2.carbon.connector</groupId>
<artifactId>org.wso2.carbon.connector.redis</artifactId>
<packaging>jar</packaging>
<version>2.6.0-SNAPSHOT</version>
<version>2.6.0</version>
<name>WSO2 Carbon - Mediation Library Connector For Redis</name>
<url>http://wso2.org</url>
<properties>
Expand Down
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();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class RedisConstants {
public static final String HOST = "redisHost";
public static final String CONNECTION_URI = "redisConnectionURI";
public static final String RESULT = "result";
public static final String RESULT_OF_IDLE = "result_of_idle";
public static final String KEY = "redisKey";
public static final String VALUE = "redisValue";
public static final String PATTERN = "redisPattern";
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/strings/component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<file>get.xml</file>
<description>get the value of a key</description>
</component>
<component name="getObjectIdleTime">
<file>getObjectIdleTime.xml</file>
<description>get the OBJECT IDLE TIME</description>
</component>
<component name="getRange">
<file>getRange.xml</file>
<description>get the sub string of the key</description>
Expand Down
37 changes: 37 additions & 0 deletions src/main/resources/strings/getObjectIdleTime.xml
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>

0 comments on commit 277afb8

Please sign in to comment.