[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
jni example with terracotta  XML
Forum Index -> General
Author Message
gmather

neo

Joined: 04/14/2008 07:28:05
Messages: 4
Offline

Hi,

I'm having some difficulty with JNI setup for Terracotta. Any suggestion on what I am doing wrong here?

Thanks,
--Thanhy

#define USER_CLASSPATH "-Xbootclasspath/p:./lib/dso-boot-hotspot_linux_150_11.jar -Dtc.install-root=/danger/local/terracotta-2.6 -Dtc.config= -Djava.class.path=./target/classes:./lib/ehcache-1.2.4.jar:./lib/commons-logging-1.0.4.jar:./lib/concurrent-1.0.jar:./lib/jcs-1.3.jar:./lib/tc.jar"

main()
{
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options[1];
options[0].optionString = USER_CLASSPATH;
int i, rc, status;
jint res;
char classpath[1024];
int total_threads = 10;
pthread_t threads[total_threads];
pthread_attr_t attr;

/* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;

#if 0
JNI_GetDefaultJavaVMInitArgs(&vm_args);

/* Append USER_CLASSPATH to the end of default system class path */
sprintf(classpath, "%s%c%s", vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
vm_args.classpath = classpath;
#endif

/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res < 0)
{
fprintf(stderr, "Can't create Java VM\n");
exit(EXIT_FAILURE);
}

//
// init()
//
jclass cls = (*env)->FindClass(env, "com/danger/cache/TCacheService");
if (cls == 0)
{
fprintf(stderr, "Can't find com.danger.cache.TCacheService class\n");
exit(EXIT_FAILURE);
}

// ...

}
tgautier

cherubim

Joined: 06/05/2006 12:19:26
Messages: 950
Offline

I don't know that we'll be able to help you - as we haven't really tried much JNI with Terracotta. However, to start with, what error are you seeing?

Regards,

Taylor Gautier
Product Manager | Terracotta, Inc.
Join the Terracotta Community
[WWW]
gmather

neo

Joined: 04/14/2008 07:28:05
Messages: 4
Offline

I got it! Here's the code to create Terracotta-enabled JVM in c.

--Thanhy

main()
{
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options[4];

options[0].optionString = "-Xbootclasspath/p:./lib/dso-boot-hotspot_linux_150_11.jar";
options[1].optionString = "-Dtc.install-root=/danger/local/terracotta-2.6";
options[2].optionString = "-Dtc.config= ";
options[3].optionString = "-Djava.class.path= .:./target/classes:./lib/tc.jar";

int i, rc, status;
jint res;
char classpath[1024];
int total_threads = 10;
pthread_t threads[total_threads];
pthread_attr_t attr;

/* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 4;
vm_args.ignoreUnrecognized = JNI_TRUE;

/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res < 0)
{
fprintf(stderr, "Can't create Java VM\n");
exit(EXIT_FAILURE);
}

// ...

}
ari

praetor

Joined: 05/24/2006 14:23:21
Messages: 242
Offline

Wow. Kewl!

What is this for though?

--Ari

Want to post to this forum? Please join the Terracotta community: Sign up
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.7 © JForum Team