Author |
Message |
07/10/2008 05:19:40
|
bhupendr
journeyman
Joined: 06/19/2008 21:00:21
Messages: 19
Offline
|
Hy All,
I have two jar file.which contains my whole application & these also use other jar files like cglib.jar .I use modules <tag>for these jar files.I made a cache class which contains information about all users which are currently login on..!,this class is singleton based.i want share whole information of this class.For this I wrote code like as
<roots>
<root>
<field-name>com.bhupendra.MyCache.instance</field-name>
</root>
................
</roots>
where::: com.bhupendra.MyCache is fully qualified class name and instance is look like as
public class MyCache {
private static MyCache instance = null;
public static MyCache getInstance()
{
if(instance==null)
{
instance = new MyCache();
}
return instance;
}
...................
......
BUT NOT WORK PROPERLY>>>>>>Exception occurs..
|
|
|
07/10/2008 07:47:53
|
amiller
ophanim
Joined: 08/29/2007 09:05:48
Messages: 722
Location: St. Louis, MO
Offline
|
Could you post the exception stack trace and your tc-config.xml? It's hard to tell what the problem is just from this description.
In your MyCache class I don't see any synchronization so that's not safe for either multi-threaded or clustered usage.
You could just do:
Code:
public class MyCache {
private static final MyCache instance = new MyCache();
public static MyCache getInstance() {
return instance;
}
}
|
Alex Miller (Terracotta Engineer) - Want to post to the forums? Sign up here |
|
|
07/10/2008 07:50:17
|
tgautier
seraphim
Joined: 06/05/2006 12:19:26
Messages: 1781
Offline
|
what exception?
By the way that is not a safe way to write a singleton. Search for singleton java or get and read Effective Java for safe singleton patterns.
|
|
|
07/10/2008 23:41:25
|
bhupendr
journeyman
Joined: 06/19/2008 21:00:21
Messages: 19
Offline
|
My whole application combinds in two jar files..One for execute that application only and other contained all core operations of that appication.If we use <modules><repository> tag,whenever I run my application ,.Exception occurs but my terminal treminates accidently....
Other situation is when I not use <modules><repository> tag,then Errors occurs
tc-config.xml is like as....
<?xml version="1.0" encoding="UTF-8"?>
<tc:tc-config xmlns:tc="http://www.terracotta.org/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd">
<!--Server is colocated with client and DSO is listening on
default port (9510).-->
<system>
<configuration-model>development</configuration-model>
</system>
<servers>
<server host="192.168.X.X" name="myApplication1">
<dso>
<client-reconnect-window>120</client-reconnect-window>
<persistence>
<mode>permanent-store</mode>
</persistence>
<garbage-collection>
<enabled>true</enabled>
<verbose>true</verbose>
<interval>3600</interval>
</garbage-collection>
</dso>
<data>terracottaServer/server-data/serverdatalog/%D</data>
<logs>terracottaServer/server-logs/lserverogslog/%D</logs>
<statistics>terracottaServer/server-statistics/statisticslog/%D</statistics>
</server>
</servers>
<clients>
<modules>
<repository>/application-3.5/1.1/lib/mycom/application</repository>
<module name="application-3.5" version="1.1" group-id="lib.mycom.application"/>
<module name="startup-3.5" version="1.1" group-id="lib.mycom.application"/>
</modules>
<logs>terracottaClient/client-logs/clientlog/%D</logs>
<statistics>terracottaClient/client-statistics/clientstatics/%D</statistics>
<dso>
<fault-count>500</fault-count>
<debugging>
<instrumentation-logging>
<class>true</class>
<locks>true</locks>
<transient-root>true</transient-root>
<roots>true</roots>
<distributed-methods>true</distributed-methods>
</instrumentation-logging>
<runtime-logging>
<non-portable-dump>true</non-portable-dump>
<lock-debug>true</lock-debug>
<wait-notify-debug>true</wait-notify-debug>
<distributed-method-debug>true</distributed-method-debug>
<new-object-debug>true</new-object-debug>
</runtime-logging>
<runtime-output-options>
<auto-lock-details>true</auto-lock-details>
<caller>true</caller>
<full-stack>true</full-stack>
</runtime-output-options>
</debugging>
</dso>
</clients>
<application>
<dso>
<instrumented-classes>
<include>
<class-expression>com.bhupendra.MyCache</class-expression>
</include>
<include>
<class-expression>com.bhupendra.MyAuthProvider</class-expression>
</include>
<include>
<class-expression>com.bhupendra.MyUserProvider</class-expression>
</include>
</instrumented-classes>
<locks>
<named-lock>
<lock-name>lockOne</lock-name>
<method-expression>* com.bhupendra.MyCache.*(..)</method-expression>
<lock-level>write</lock-level>
</named-lock>
</locks>
<roots>
<root>
<field-name>com.bhupendra.MyCache.instance</field-name>
<root-name>rootOne</root-name>
</root>
</roots>
</dso>
</application>
</tc:tc-config>
And Exception like as.......
2008-07-11 12:05:32,398 [main] INFO com.terracottatech.dso.instrumentation - Inserting named lock in com.bhupendra.MyCache.putIdInCacheByUserName(Ljava/lang/String;Ljava/lang/Long;)V
name: lockOne, level: write
2008-07-11 12:05:32,448 [main] INFO com.terracottatech.dso.runtime - Named lock [^lockOne] acquired with level WRITE (2)
at com.bhupendra.MyCache.<init>(MyCache.java:11)
at com.bhupendra.MyCache.<clinit>(MyCache.java:9)
at com.bhupendra.MyAuthProvider.<init>(MyAuthProvider.java:37)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at java.lang.Class.newInstance0(Class.java:350)
at java.lang.Class.newInstance(Class.java:303)
...............
..............................
2008-07-11 12:05:32,461 [main] ERROR com.tc.object.bytecode.Manager - Exception thrown
java.lang.IllegalStateException: Classloader name not set, instances defined from this loader not supported in Terracotta (loader: org.my.application.starter.MyClassLoader)
at java.lang.ClassLoader.__tc_getClassLoaderName(ClassLoader.java)
at com.tc.object.loaders.StandardClassProvider.getName(StandardClassProvider.java:67)
at com.tc.object.loaders.StandardClassProvider.getLoaderDescriptionFor(StandardClassProvider.java:79)
at com.tc.object.loaders.StandardClassProvider.getLoaderDescriptionFor(StandardClassProvider.java:74)
at com.tc.object.TCClassFactoryImpl.getOrCreate(TCClassFactoryImpl.java:58)
at com.tc.object.ClientObjectManagerImpl.getPortableObjects(ClientObjectManagerImpl.java:241)
at com.tc.object.Traverser.addReferencedObjects(Traverser.java:37)
at com.tc.object.Traverser.traverse(Traverser.java:81)
at com.tc.object.ClientObjectManagerImpl.addToManagedFromRoot(ClientObjectManagerImpl.java:982)
at com.tc.object.ClientObjectManagerImpl.create(ClientObjectManagerImpl.java:338)
at com.tc.object.ClientObjectManagerImpl.lookupOrCreateIfNecesary(ClientObjectManagerImpl.java:402)
at com.tc.object.ClientObjectManagerImpl.lookupOrCreate(ClientObjectManagerImpl.java:380)
at com.tc.object.ClientObjectManagerImpl.lookupRootOptionallyCreateOrReplace(ClientObjectManagerImpl.java:909)
at com.tc.object.ClientObjectManagerImpl.lookupOrCreateRoot(ClientObjectManagerImpl.java:702)
at com.tc.object.ClientObjectManagerImpl.lookupOrCreateRoot(ClientObjectManagerImpl.java:685)
at com.tc.object.bytecode.ManagerImpl.lookupOrCreateRoot(ManagerImpl.java:303)
.............
........................
|
|
|
07/11/2008 04:48:13
|
amiller
ophanim
Joined: 08/29/2007 09:05:48
Messages: 722
Location: St. Louis, MO
Offline
|
Ok, several things here:
1. The modules tag is used to include Terracotta Integration Modules, which are bundles of Terracotta configuration (or occasionally code) typically for including the clustered config for a 3rd party library. You can use them to bundle up your own config, but it looks to me like you're using them to include your normal jar files, which is not an expected usage. You should just include these jars in your classpath.
2. It seems like the real problem here is that you are using a custom classloader that doesn't conform to the Terracotta "named classloader" rules. This is relatively easy to do - can you post some more info on org.my.application.starter.MyClassLoader? Does it extend URLClassLoader?
3. You're using named locks which are generally not recommended - it's almost always better to just use an autolock. In this example, I don't see any reason for it. This isn't a big deal, just a tip.
|
Alex Miller (Terracotta Engineer) - Want to post to the forums? Sign up here |
|
|
07/13/2008 21:36:25
|
bhupendr
journeyman
Joined: 06/19/2008 21:00:21
Messages: 19
Offline
|
Hy Miller.....,
MyClassLoader class extends URLClassLoader class and its code is as ........
import java.io.File;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
class MyClassLoader extends URLClassLoader {
MyClassLoader(ClassLoader parent, File libDir) throws MalformedURLException {
super(new URL[] { libDir.toURL() }, parent);
File[] jars = libDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
boolean flag = false;
String smallData = name.toLowerCase();
if (smallData.endsWith(".jar")) {
flag = true;
}
else if (smallData.endsWith(".zip")) {
flag = true;
}
return flag;
}
});
// Do nothing if no jar or zip files were found
if (jars == null) {
return;
}
for (int i = 0; i < jars.length; i++) {
if (jars[i].isFile()) {
addURL(jars[i].toURL());
}
}
}
}
|
|
|
07/15/2008 13:50:44
|
teck
seraphim
Joined: 05/24/2006 15:03:25
Messages: 1128
Offline
|
To use your own classloader you need to assign a "name" to it and register it with Terracotta. The reason this is necessary is that in order to materialize the object on another VM you'll want the same classloader (logically) to be used. NOTE: The instructionts provided below are mostly a workaround, the use of user defined classloaders isn't officially supported
This post has the information you need:
http://forums.terracotta.org/forums/posts/list/590.page
In a nutshell you need to something like this:Code:
ClassLoader loader = new MyClassLoader(..);
((NamedClassLoader) loader).__tc_setClassLoaderName("some-unique-description-of-your-loader-instance");
ClassProcessorHelper.registerGlobalLoader((NamedClassLoader) loader);
To compile this code you will need to include the terracotta dso-boot jar in your compile time classpath. You do not need (or want) to add this jar your runtime CLASSPATH, just need it at compile time.
If you have more than one instance of MyClassLoader, you'll want to assign them different loader names.
I should have mentioned this at the beginning, but if you an avoid clustering objects defined by your own custom classloaders, that would be the easiest thing to do :-). The standard system loaders and those created by supported web containers should work transparently w/o any special code.
|
Tim Eck (terracotta engineer)
|
|
|
07/15/2008 13:59:54
|
amiller
ophanim
Joined: 08/29/2007 09:05:48
Messages: 722
Location: St. Louis, MO
Offline
|
It also seems like your custom classloader isn't actually doing anything special, just building a set of urls. You could accomplish the same thing by putting the code from your constructor in a method and calling the URLClassLoader constructor with the urls.
|
Alex Miller (Terracotta Engineer) - Want to post to the forums? Sign up here |
|
|
|