Re: JNDI object not shared among TC instances
On Tue, Dec 14, 2004 at 08:52:17AM -0500, Shapira, Yoav wrote: > > Thanks Joav and for the other people stumbling on the same rock > > You're welcome -- and it's Yoav with a Y ;) > > > and by the way why don't they use a search box at > >http://jakarta.apache.org/tomcat/faq/ ? > > Because we'll all Googleheads who routinely do inurl: searches. The > search box is a decent idea, thanks for bringing it up. It's fairly straightforward (and I've seen it in use several other sites) to just put a form in the page that submits to google with an inurl: parameter. Probably the quickest & easiest way to add search to the page. Ah... a little poking around shows it's documented at: See http://news.google.com/searchcode.html However, they don't explain how to do an inurl: search. A little experimenting shows you can submit both a q and as_q parameter, and put the inurl: in a q input. I just whipped up a quick example, it's at http://darksleep.com/notablog/google.html -- Steven J. Owens [EMAIL PROTECTED] "I'm going to make broad, sweeping generalizations and strong, declarative statements, because otherwise I'll be here all night and this document will be four times longer and much less fun to read. Take it all with a grain of salt." - http://darksleep.com/notablog - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JNDI object not shared among TC instances
> Why would you expect this to be possible? > JNDI defines an API for a directory . . . Nope! JNDI stands for Java Naming and Directory Interface (JNDI) check out java.sun.com/products/jndi/ most 'Naming' services work is based on networking protocols even many of those looking like file/directory ones > Once you involve multiple JVMs, you need some sort of object sharing and/or persistence system to allow code in multiple JVM's to look up 'the same' objects. . . . object sharing . . ., which I (to a certain extent wrongly or wishfully thining) understood to be provided by JNDI. The 'persistence' part of it I can be taken care of by other subsystem or yourself > Some of us used to work on Object Oriented Databases for this purpose One way to go - Original Message - From: "Benson Margulies" <[EMAIL PROTECTED]> To: "Tomcat Users List" <[EMAIL PROTECTED]> Sent: Monday, December 13, 2004 9:31 PM Subject: RE: JNDI object not shared among TC instances Why would you expect this to be possible? JNDI defines an API for a directory. Inside one JVM, it's simple technology to use that API to look up Java objects. Once you involve multiple JVMs, you need some sort of object sharing and/or persistence system to allow code in multiple JVM's to look up 'the same' objects. Some of us used to work on Object Oriented Databases for this purpose --- EJBs are another view. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: JNDI object not shared among TC instances
Why would you expect this to be possible? JNDI defines an API for a directory. Inside one JVM, it's simple technology to use that API to look up Java objects. Once you involve multiple JVMs, you need some sort of object sharing and/or persistence system to allow code in multiple JVM's to look up 'the same' objects. Some of us used to work on Object Oriented Databases for this purpose --- EJBs are another view. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JNDI object not shared among TC instances
Thanks Joav and for the other people stumbling on the same rock and by the way why don't they use a search box at http://jakarta.apache.org/tomcat/faq/ ? I had to click in, search and and click out of it again for every faq topic!!!??? OK, I found the answer here: http://jakarta.apache.org/tomcat/faq/misc.html#externalJndi Can I access Tomcat's JNDI provider from outside tomcat? Not at this time. The question/answer should be worded/extended like . . . Even different Tomcat instances use different JNDI contexts, . . . and here: http://jakarta.apache.org/tomcat/faq/misc.html#ejb Is tomcat an EJB server? Can I use EJBs with tomcat? Tomcat is not an EJB server. Tomcat is not a full J2EE server. Tomcat is a Servlet container. Tomcat does support those parts of the J2EE specification that are required for Servlets, such as a subset of JNDI functionality. Furthermore, you can connect to remote J2EE servers, or run tomcat embedded inside a full J2EE server. Now I see, I was getting a little too fancy, I will have to use EJBs - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JNDI object not shared among TC instances
Hmm! I beg your pardon, but I will have to ask you a very basic question, indeed :-) Which FAQ do you mean? Tomcat's, JNDI's or Java's? I went off crazy looking for it and I couldn't find it. I thought I had exhausted all other ways to understand this problem . . . and thanks for sheding light into it. If it is impossible to do things the way I thought I could, I will have to work around it somehow, problably keeping all data structuring the objects' states in a backend database tables I still have a kind of conceptual/phylosophical question. How do you set up a singleton that would be such for different JVMs instances, from different JVMs vendors, different boxes and networks, based on plain JNDI (I mean without EJBs or DBMS replication)? Or, . . . am I day dreaming? I really thought this was what JNDI was all about and even EJBs naming was based on JNDI. Thanks - Original Message - From: "Shapira, Yoav" <[EMAIL PROTECTED]> To: "Tomcat Users List" <[EMAIL PROTECTED]> Sent: Monday, December 13, 2004 8:59 AM Subject: RE: JNDI object not shared among TC instances Hi, Tomcat's JNDI implementation does not support sharing for that matter even external connections. (This is in the FAQ by the way). If you want to share an object among multiple Tomcat instances via JNDI, you must use a JNDI provider that supports this. Yoav Shapira http://www.yoavshapira.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: JNDI object not shared among TC instances
Hi, > Thanks Joav and for the other people stumbling on the same rock You're welcome -- and it's Yoav with a Y ;) > and by the way why don't they use a search box at >http://jakarta.apache.org/tomcat/faq/ ? Because we'll all Googleheads who routinely do inurl: searches. The search box is a decent idea, thanks for bringing it up. Yoav Shapira http://www.yoavshapira.com This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: JNDI object not shared among TC instances
Hi, Tomcat's JNDI implementation does not support sharing for that matter even external connections. (This is in the FAQ by the way). If you want to share an object among multiple Tomcat instances via JNDI, you must use a JNDI provider that supports this. Yoav Shapira http://www.yoavshapira.com >-Original Message- >From: John Smith [mailto:[EMAIL PROTECTED] >Sent: Sunday, December 12, 2004 1:12 AM >To: "Tomcat Users List" >Subject: JNDI object not shared among TC instances > >Hi, > > as, I understand things, the JNDI can be used to share an object among >different JVMs even from J2SE applications running on different machines. >Right? > > I need a relatively light object (that is why I am avoiding EJBs >altogether) which would simply: > 1._ poll a backend database at configurable periods, and if some data has >changed > 2._ update its internal state, which is then > 3._ administered to and updated in a number of independent tomcat >instances > > Well, I did the following exp. and repeated it even compiling TC 5.5.5 >from >source in case I had to check it, but before I start diving deeper into >what >I think might be the reason for this anomaly, I want to check that I don't >have a silly conf problem I haven't seen or there is something I am not >quite understanding here. > > Here is the method to my madness: > > 1._ I first downloaded TC's source code, 'built it' with ant, ran and >tested it. > 2._ Then I set up a number (3) of separate instances running from >independent JVMs using the same files as in the original, plain >installation, as describe in 1; by: > 2.1_ setting up three independent directories, <...> /tc00/, /tc02/, and >/tc04/ off the original installation > 2.2_ just copying /conf/ and /bin/ from the original installation and >dumping similar files on each dir described in 2.1 > 2.3_ changing then in each of the /conf/server.xml > 2.3.1_ the Server port="8005" > 2.3.2_ the non-SSL HTTP/1.1 Connector port="8080" > 2.3.3_ the AJP 1.3 Connector port="8009" (<- will need it for later >tinkering with Apache) >for all three independent instances, and > 2.4_ making sure that the same absolute directory was used in the appBase >attribute of the2.5_ then, making sure that the same; > 2.5.1_ JAVA_HOME > 2.5.2_ CATALINA_HOME >but different > 2.5.3_ CATALINA_BASE >was set in the respective .../tcXX/bin/catalina.bat files (client wants me >to 'try' windows 'too'), pointing to the respective .../tcXX > 3._ I then run all three instances and tested every thing was OK and scan >log files for any errors, warnings, . . . > > Everything seemed to be working just fine! > >// - - - - - - - - - - - - - - - - - - - - - > > Then I used the following slimmed down classes from example code sections >in the jakarta JNDI howto, in order to illustrate my point. > > Both classes were placed in the original installation's >/common/classes/JNDITest/ directory > >// - - - - - - - - - - - - - - - - - - - - - >package JNDITest; > >public class JNDI00{ > private int bar = 0; > private long lCreatTime = System.currentTimeMillis(); > private String foo = "Default Foo, created at " + lCreatTime + ""; >// __ > public String getFoo() { return (this.foo); } > public void setFoo(String foo) { this.foo = foo; } >// __ > public int getBar() { return (this.bar); } > public void setBar(int bar) { this.bar = bar; } >// __ > public long getCreatTime() { return (lCreatTime); } > public void setCreatTime(long l){} >// __ >} > >// - - - - - - - - - - - - - - - - - - - - - >package JNDITest; > >import java.util.*; >import javax.naming.*; >import javax.naming.spi.*; > >public class JNDI00Factory implements ObjectFactory { > > public Object getObjectInstance(Object obj, Name name, Context nameCtx, >Hashtable environment) throws NamingException { > > JNDI00 JNDI_Obj = new JNDI00(); > > Reference ref = (Reference) obj; > Enumeration addrs = ref.getAll(); > while (addrs.hasMoreElements()) { > RefAddr addr = (RefAddr) addrs.nextElement(); > String aSNm = addr.getType(); > String value = (String) addr.getContent(); > if (aSNm.equals("foo")) { > JNDI_Obj.setFoo(value); > } else if (aSNm.equals("bar")) { > try { > JNDI_Obj.setBar(Integer.parseInt(value)); > } catch (NumberFormatException e) { > throw new NamingException("Invalid 'bar' value " + >value); > } >
JNDI object not shared among TC instances
Hi, as, I understand things, the JNDI can be used to share an object among different JVMs even from J2SE applications running on different machines. Right? I need a relatively light object (that is why I am avoiding EJBs altogether) which would simply: 1._ poll a backend database at configurable periods, and if some data has changed 2._ update its internal state, which is then 3._ administered to and updated in a number of independent tomcat instances Well, I did the following exp. and repeated it even compiling TC 5.5.5 from source in case I had to check it, but before I start diving deeper into what I think might be the reason for this anomaly, I want to check that I don't have a silly conf problem I haven't seen or there is something I am not quite understanding here. Here is the method to my madness: 1._ I first downloaded TC's source code, 'built it' with ant, ran and tested it. 2._ Then I set up a number (3) of separate instances running from independent JVMs using the same files as in the original, plain installation, as describe in 1; by: 2.1_ setting up three independent directories, <...> /tc00/, /tc02/, and /tc04/ off the original installation 2.2_ just copying /conf/ and /bin/ from the original installation and dumping similar files on each dir described in 2.1 2.3_ changing then in each of the /conf/server.xml 2.3.1_ the Server port="8005" 2.3.2_ the non-SSL HTTP/1.1 Connector port="8080" 2.3.3_ the AJP 1.3 Connector port="8009" (<- will need it for later tinkering with Apache) for all three independent instances, and 2.4_ making sure that the same absolute directory was used in the appBase attribute of theelement of $CATALINA_HOME/conf/server.xml // - - - - - - - - - - - - - - - - - - - - - in $CATALINA_HOME/conf/ Catalina/localhost/ROOT.xml // - - - - - - - - - - - - - - - - - - - - - and at the end of $CATALINA_HOME/webapps/ROOT/WEB-INF/web.xml JNDICtxt JNDI00Factory Test jndiName JNDITest.JNDI00 // - - - - - - - - - - - - - - - - - - - - - Then included right on /ROOT/index.jsp code segments looking like: <%@ page language="java" %> <%@ page import="java.util.*" %> <%@ page import="java.io.*" %> <%@ page import="javax.naming.*" %> <%@ page import="JNDItest.*" %> <%@ page session="false" %> <%! // __ private Context initCtxt; private Context envCtxt; private JNDI00 JNDIObj; // __ public void jspInit(){ // __ JNDI resources String aBug = ""; // __ try{ initCtxt = new InitialContext(); envCtxt = (Context)initCtxt.lookup("java:comp/env"); // __ String aInitCtxt = initCtxt.toString(); String aEnvCtxt = envCtxt.toString(); // __ aBug += "initCtxt: " + aInitCtxt + ""; aBug += "EnvCtxt: " + aEnvCtxt + ""; // __ System.err.println(" initCtxt: |" + initCtxt + "|"); System.err.println(" envCtxt: |" + envCtxt + "|"); // __ System.err.println(" (new JNDI00()): |" + (new JNDI00()) + "|"); // __ String aCtxtURL = "JNDICtxt/JNDI00Factory"; aCtxtURL = "jndiName"; JNDIObj = (JNDI00)envCtxt.lookup(aCtxtURL); System.err.println(" JNDIObj: |" + JNDIObj + "|"); if(JNDIObj != null){ System.err.println(" JNDIObj: |" + JNDIObj + "|"); System.err.println(" JNDIObj.getBar(): |" + (new Integer(JNDIObj.getBar())).toString() + "|"); System.err.println(" JNDIObj.getCreatTime(): |" + JNDIObj.getCreatTime() + "|"); System.err.println(" JNDIObj.getFoo(): |" + JNDIObj.getFoo() + "|"); // __ aBug += "JNDIObj: |" + JNDIObj.toString() + "|"; aBug += "JNDIObj.getBar(): |" + (new Integer(JNDIObj.getBar())).toString() + "|"; aBug += "JNDIObj.getCreatTime(): |" + JNDIObj.getCreatTime() + "|"; aBug += "JNDIObj.getFoo(): |" + JNDIObj.getFoo() + "|"; } // __ aBug += ""; }catch(NamingException NmX){ NmX.printStackTrace(); } // __ }// jspInit() // __ public void JspDestroy(){} %> <% // __ Response Headers response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); // __ %> // - - - - - - - - - - - - - - - - - - - - - and inside the actual page just after <%=aBug%> // - - - - - - - - - - - - - - - - - - - - - You will see each TC instance has its own instances of: * javax.naming.InitialContext * org.apache.naming.NamingContext * JNDITest.JNDI00 What is it I am doing wrong here? How could you achieve what I want, namely, read (kind of a singleton object from different TOmcat instances? "Any help would be appreciated" - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]