Debanjan Sarkar

Greenhorn
+ Follow
since Aug 08, 2015
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Debanjan Sarkar

Hey,
I also tried with a different xml config but still got the same result. I am pasting the config here:
<?xml version="1.0"?>
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">

<cache-config>
<defaults>
<serializers>pof</serializers>
</defaults>
<caching-scheme-mapping>
<!-- Caches with any name will be created as default replicated. -->
<cache-mapping>
<cache-name>VirtualCache</cache-name>
<scheme-name>MyNearScheme</scheme-name>
</cache-mapping>

</caching-scheme-mapping>

<caching-schemes>
<near-scheme>
<scheme-name>MyNearScheme</scheme-name>

<front-scheme>
<local-scheme>
<eviction-policy>LRU</eviction-policy>
<high-units>5</high-units>
<unit-calculator>FIXED</unit-calculator>
<expiry-delay>1h</expiry-delay>
</local-scheme>
</front-scheme>

<back-scheme>
<distributed-scheme>
<scheme-name>near-distributed</scheme-name>
<backing-map-scheme>
<local-scheme>
<high-units>100</high-units>
<unit-calculator>FIXED</unit-calculator>
</local-scheme>
</backing-map-scheme>
<autostart>true</autostart>
</distributed-scheme>
</back-scheme>

<invalidation-strategy>present</invalidation-strategy>

</near-scheme>
</caching-schemes>
</cache-config>
Yes Rob,
I have a config file named coherence-cache-config.xml in my /src/main/resources classpath folder
The contents are as follows:
<?xml version="1.0"?>
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">

<cache-config>
<caching-scheme-mapping>
<!-- Caches with any name will be created as default replicated. -->
<cache-mapping>
<cache-name>*</cache-name>
<scheme-name>default-replicated</scheme-name>
</cache-mapping>
<cache-mapping>
<cache-name>VirtualCache</cache-name>
<scheme-name>default-distributed</scheme-name>
</cache-mapping>
</caching-scheme-mapping>

<caching-schemes>
<!-- Default Replicated caching scheme. -->
<replicated-scheme>
<scheme-name>default-replicated</scheme-name>
<service-name>ReplicatedCache</service-name>

<backing-map-scheme>
<class-scheme>
<scheme-ref>default-backing-map</scheme-ref>
</class-scheme>
</backing-map-scheme>
</replicated-scheme>

<!-- Default Distributed caching scheme. -->
<distributed-scheme>
<scheme-name>default-distributed</scheme-name>
<service-name>DistributedCache</service-name>

<backing-map-scheme>
<class-scheme>
<scheme-ref>default-backing-map</scheme-ref>
</class-scheme>
</backing-map-scheme>
</distributed-scheme>

<!-- Default backing map scheme definition used by all The caches that
do not require any eviction policies -->
<class-scheme>
<scheme-name>default-backing-map</scheme-name>

<class-name>com.tangosol.util.SafeHashMap</class-name>
</class-scheme>

</caching-schemes>
</cache-config>
Hi Rob,
My other thread was locked so I have to paste the rectified information here as a comment. Please check this out.
Value of the NamedCache variable cache after calling getCache(): null
Exception in thread "main" java.lang.NullPointerException
at com.learn.coherence.main.TestCacheMainOne.main(TestCacheMainOne.java:9)

The code is fairly simple and small. I am marking the line causing this exception in bold.
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
public class TestCacheMainOne {
public static void main(String[] args) {
NamedCache cache = CacheFactory.getCache("VirtualCache");
System.out.println("Value of the NamedCache variable cache after calling getCache(): " + cache);
String key = "key1";
String value = "value1";
cache.put(key, value);
String receivedValue = (String) cache.get(key);
System.out.println(receivedValue);
}
}
Hi again Rob.
Yeah you are correct, I screwed up the line numbers while trying to compact the code. I have made a new post with some more details and proper information here: https://coderanch.com/t/656371/java/java/NPE-caching-coherence-java#3039681
Can you please check this out? Thanks in advance.
Hi Ranchers,

I am trying to build a simple caching application using coherence. I am able to bring up the service by running cache-server.cmd from the directory where coherence was installed (C:\Oracle\Middleware\Oracle_Home\coherence\bin) and push or pop value from the cache via command line (cmd). But when I try to do the same using Java code, I am getting the following error:
Value of the NamedCache variable cache after calling getCache(): null
Exception in thread "main" java.lang.NullPointerException
at com.learn.coherence.main.TestCacheMainOne.main(TestCacheMainOne.java:9)

The code is fairly simple and small. I am marking the line causing this exception in bold.
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
public class TestCacheMainOne {
public static void main(String[] args) {
NamedCache cache = CacheFactory.getCache("VirtualCache");
System.out.println("Value of the NamedCache variable cache after calling getCache(): " + cache);
String key = "key1";
String value = "value1";
cache.put(key, value);
String receivedValue = (String) cache.get(key);
System.out.println(receivedValue);
}
}

Please help me in getting over this obstacle.
4 years ago
Hi Ranchers,

I am trying to build a simple caching application using coherence. I am able to bring up the service and push or pop value from the cache via command line (cmd). But when I try to do the same using Java code, I am getting the following error:
null
Exception in thread "main" java.lang.NullPointerException
at com.learn.coherence.main.TestCacheMainOne.main(TestCacheMainOne.java:14)

The code is fairly simple and small. I am marking the line causing this exception in bold.

import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
public class TestCacheMainOne {
public static void main(String[] args) {
NamedCache cache = CacheFactory.getCache("VirtualCache");
System.out.println(cache);
String key = "key1";
String value = "value1";
cache.put(key, value);
String receivedValue = (String) cache.get(key);
System.out.println(receivedValue);
}
}

Please help me regarding this. I have a very stringent deadline to beat. Kindly help.
Hi,
I have two projects running. My goal is to create a cache in the first application and then access this cache from the second project.
The code is as follows:

Project1:
public class ErrorLogCacheManagerMain {

public static JCS cache;
public static void main(String[] args) throws Exception {
cache = JCS.getInstance( "errorLogCache" );
String url = "jdbc:oracle:thin:@localhost:1521:sysdba";
Properties props = new Properties();
props.setProperty("user", "dev");
props.setProperty("password", "dev123");
Connection conn = DriverManager.getConnection(url,props);
String sql ="SELECT * from DEV.ERROR_LOG";
String groupName = "group1";
ArrayList<ErrorLogEntity> errorLogEntityList = new ArrayList<ErrorLogEntity>();
PreparedStatement preStatement = conn.prepareStatement(sql);

ResultSet result = preStatement.executeQuery();

while(result.next()){
ErrorLogEntity errorLogEntity = new ErrorLogEntity();
errorLogEntity.setAddDate(result.getDate("ADD_DATE"));
errorLogEntity.setErId(result.getInt("ER_ID"));
errorLogEntity.setErrorDesc(result.getString("ER_DESC"));
errorLogEntity.setErrorStatus(result.getInt("ER_STATUS"));
errorLogEntity.setFlag(result.getString("SENT_FLAG"));
errorLogEntity.setRefId(result.getString("REF_ID"));
cache.putInGroup(errorLogEntity.getErId(), groupName, errorLogEntity);
errorLogEntity = null;
}
Set keys = cache.getGroupKeys(groupName);
for(Object key : keys) {
System.out.println(key);
ErrorLogEntity errorLogEntity = (ErrorLogEntity) cache.getFromGroup(key, groupName);
System.out.println(errorLogEntity);
System.out.println(errorLogEntity.getErId());
System.out.println(errorLogEntity.getRefId());
System.out.println(errorLogEntity.getAddDate());
System.out.println(errorLogEntity.getErrorDesc());
System.out.println(errorLogEntity.getErrorStatus());
System.out.println(errorLogEntity.getFlag());
}
}
}
cache.ccf 1:
# DEFAULT CACHE REGION
jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.UseMemoryShrinker=true
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
jcs.default.cacheattributes.DiskUsagePatternName=UPDATE
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.elementattributes.MaxLifeSeconds=21600
jcs.default.elementattributes.IdleTime=1800
jcs.default.elementattributes.IsSpool=true
jcs.default.elementattributes.IsRemote=true
jcs.default.elementattributes.IsLateral=true

# PREDEFINED CACHE REGIONS
jcs.region.errorLogCache=DC
jcs.region.errorLogCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.errorLogCache.cacheattributes.MaxObjects=1000
jcs.region.errorLogCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.errorLogCache.cacheattributes.UseMemoryShrinker=true
jcs.region.errorLogCache.cacheattributes.MaxMemoryIdleTimeSeconds=20
jcs.region.errorLogCache.cacheattributes.ShrinkerIntervalSeconds=10
jcs.region.errorLogCache.cacheattributes.MaxSpoolPerRun=500
jcs.region.errorLogCache.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.errorLogCache.elementattributes.IsEternal=false

# AVAILABLE AUXILIARY CACHES
jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=C:/Users/Debanjan/Desktop/Exp
jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000000
jcs.auxiliary.DC.attributes.MaxKeySize=1000000
jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
jcs.auxiliary.DC.attributes.ShutdownSpoolTimeLimit=60


Project 2:
public class CacheMainTest {

public static JCS cache;
public static String groupName = "group1";
public static void main(String[] args) throws InterruptedException, CacheException {
cache = JCS.getInstance( "errorLogCache" );
System.out.println(cache);
Set keys = cache.getGroupKeys(groupName);
System.out.println(keys);
for(Object key : keys) {
System.out.println(key);
ErrorLogEntity errorLogEntity = (ErrorLogEntity) cache.getFromGroup(key, groupName);
System.out.println(errorLogEntity);
System.out.println(errorLogEntity.getErId());
System.out.println(errorLogEntity.getRefId());
System.out.println(errorLogEntity.getAddDate());
System.out.println(errorLogEntity.getErrorDesc());
System.out.println(errorLogEntity.getErrorStatus());
System.out.println(errorLogEntity.getFlag());
}

}
}

cache.ccf 2 :
same as cache.ccf 1

It works fine when I access the cache from within project 1. But when I try to do the same from project 2, I get the follwoing:
[ main] CompositeCacheManager INFO Creating cache manager from config file: /cache.ccf
[ main] ThreadPoolManager INFO thread_pool.default PoolConfiguration = useBoundary = [true] boundarySize = [2000] maximumPoolSize = [150] minimumPoolSize = [4] keepAliveTime = [300000] whenBlockedPolicy = [RUN] startUpSize = [4]
[ main] CompositeCacheConfigurator INFO Setting default auxiliaries to DC
[ main] CompositeCacheConfigurator INFO setting defaultCompositeCacheAttributes to [ useLateral = true, useRemote = true, useDisk = true, maxObjs = 1000, maxSpoolPerRun = -1, diskUsagePattern = 1 ]
[ main] CompositeCacheConfigurator INFO setting defaultElementAttributes to [ IS_LATERAL = true, IS_SPOOL = true, IS_REMOTE = true, IS_ETERNAL = false, MaxLifeSeconds = 21600, IdleTime = 1800, CreateTime = 1444248197766, LastAccessTime = 1444248197766, getTimeToLiveSeconds() = 21600, createTime = 1444248197766 ]
[ main] LRUMemoryCache INFO initialized LRUMemoryCache for errorLogCache
[ main] CompositeCache INFO Constructed cache with name [errorLogCache] and cache attributes [ useLateral = true, useRemote = true, useDisk = true, maxObjs = 1000, maxSpoolPerRun = 500, diskUsagePattern = 0 ]
[ main] IndexedDiskCache INFO Region [errorLogCache] Cache file root directory: C:/Users/Debanjan/Desktop/Exp
[ main] IndexedDiskCache INFO Region [errorLogCache] Set maxKeySize to: '1000000'
[ main] IndexedDiskCache INFO Region [errorLogCache] Indexed Disk Cache is alive.
[ main] CompositeCacheConfigurator INFO Parsed regions [errorLogCache]
[ main] CompositeCacheConfigurator INFO Finished configuration in 235 ms.
org.apache.jcs.JCS@71dac704
[]
[ Thread-1] IndexedDiskCache WARN Region [errorLogCache] Disk cache not shutdown properly, shutting down now.
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 0
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 1
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 2
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 3
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 4
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 5
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 6
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 7
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 8
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 9
[ndexedDiskCache-DisposalThread] IndexedDisk ERROR java.lang.IllegalStateException: Failed to delete errorLogCache.key
[ndexedDiskCache-DisposalThread] IndexedDiskCache ERROR Region [errorLogCache] Problem storing keys.
java.lang.IllegalStateException: Failed to delete errorLogCache.key
at org.apache.jcs.auxiliary.disk.indexed.IndexedDisk.reset(IndexedDisk.java:269)
at org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache.saveKeys(IndexedDiskCache.java:383)
at org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache.disposeInternal(IndexedDiskCache.java:976)
at org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache.access$000(IndexedDiskCache.java:60)
at org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache$1.run(IndexedDiskCache.java:924)
at java.lang.Thread.run(Thread.java:745)
[ndexedDiskCache-DisposalThread] IndexedDiskCache INFO Region [errorLogCache] Shutdown complete.
4 years ago
Hi,
I am trying to learn caching in Java using APIs such as JCS.
However, I haven't been able to figure out how to store results from DB queries into the cache.
Does any one here have a sample code snippet or project that you can share and help me out. I am looking for JCS examples.

Thanks in advance.
4 years ago
Hi,
I am trying to learn caching in Java using APIs such as jcs(preferred)/ehcache.
However, I haven't been able to figure out how to store results from DB queries into the caches.
Does any one here have a sample code snippet or project that you can share and help me out. I am looking for JCS examples but Ehcache will also be adequate.

Thanks in advance.
4 years ago
Right. The only time I got a compile error was when I hadn't put in the List<ErrorLogTwoEntity> typecast for em.find. Thanks for the insight.
Hey Rob,
Thanks a ton for the quick response to my post. Now that you mention it, it seems only natural. I was under the impression that it would return a list of size one with the one entry in it. Thanks for the clarification.
👍
Hi,
I am learning the java persistence API and I have run into a problem.
I get this exception:
[ main] Version INFO HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
[ main] Version INFO HHH000412: Hibernate Core {4.2.7.Final}
[ main] Environment INFO HHH000206: hibernate.properties not found
[ main] Environment INFO HHH000021: Bytecode provider name : javassist
[ main] rManagerConnectionProviderImpl INFO HHH000402: Using Hibernate built-in connection pool (not for production use!)
[ main] rManagerConnectionProviderImpl INFO HHH000115: Hibernate connection pool size: 20
[ main] rManagerConnectionProviderImpl INFO HHH000006: Autocommit mode: true
[ main] rManagerConnectionProviderImpl INFO HHH000401: using driver [oracle.jdbc.OracleDriver] at URL [jdbc:oracle:thin:[dev/dev123]@//localhost:1521/sysdba]
[ main] rManagerConnectionProviderImpl INFO HHH000046: Connection properties: {user=dev, password=****, autocommit=true, release_mode=auto}
[ main] Dialect INFO HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
[ main] TransactionFactoryInitiator INFO HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
[ main] ASTQueryTranslatorFactory INFO HHH000397: Using ASTQueryTranslatorFactory
Exception in thread "main" java.lang.ClassCastException: com.onetomany.test.ErrorLogTwoEntity cannot be cast to java.util.List
at com.onetomany.test.TestOneToManyMain.main(TestOneToManyMain.java:23)


when I run my code:
package com.onetomany.test;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class TestOneToManyMain {
private static final String PERSISTENCE_UNIT_NAME = "myModel";
private static EntityManagerFactory factory;
public static void main(String[] args) {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
List<ErrorLogTwoEntity> errorLogTwoEntityList = (List<ErrorLogTwoEntity>) em.find(ErrorLogTwoEntity.class, 2L);
//some printing
em.close();
}
}

Please help regarding this issue. Thanks in advance.
Hi Dilip,
I am new to this also but this might help
Add the following code to your work() instead of CamelContext context = new DefaultCamelContext ();

ApplicationContext springcontext = new FileSystemXmlApplicationContext("src/main/resources/beans.xml");
CamelContext context = springcontext.getBean("camel", CamelContext.class);

Please let me know if that helped
4 years ago
Hi,
Good Evening. I am pretty new to the world of spring and java.
I am trying to write a program that will use a camel route and once we have some input it goes to a processor and does some DB transactions. The problem I am facing is that when I do a
OneService oneService = exchange.getContext().getRegistry().lookupByNameAndType("OneServiceImpl", OneService.class);
this returns a null and I am not able to call any methods in the daoImpl. Can someone please help me with this. The source code is attached as a zip file.
Please help as your earliest convenience as I have a very stringent deadline to beat.
Thanks in advance.
4 years ago
Hi Karthik Shiraly,
Thank you so much for taking the time out to help me. After a little digging I decided to go with spring DSL + camel + activemq approach.
The info you provided was crucial in solving this. Since, I am so new to this field, I never realized I was actually trying to run an embedded broker at all. Pretty confusing these beans. :P
But, thanks to your help now I have a fully functional code and a better understanding of all 3 APIs.
Sincerest Thanks,
Debanjan Sarkar.
5 years ago