startup task

Poster Content
nk4um User
Posts: 24
February 4, 2010 23:18ok, I got it to work
Not sure how, but it did.
nk4um User
Posts: 24
February 4, 2010 23:08nifty fragment....
It''s a nifty fragment, but it doesn''t work anywhere I have tried putting it so far.

I can''t find any documentation that clearly explains how the sections of the nk4 module.xml relate to each other (or with practical information, such as where to put the sort of fragment you quote)

Can you offer some sort of clue?  A full example of how to invoke someting on startup, with all the pieces shown in context, is really what I need.

Since the fragments don''t work out of context, just giving one to me doesn''t help without explaining where it goes.


Thanks,
  -= miles =-
nk4um Moderator
Posts: 485
February 4, 2010 21:33Groovy runtime not imported
Hi Miles,

<id>Request Resolution Failure</id>
<message>SOURCE active:groovy+operator@res%3A/web/courtResults.groovy as Object</message>

This indicates that you don''t have the groovy module imported into the space which contains the StartingEndpoint.

You can import it with this fragment in your module definition:
<import>
  <uri>urn:org:netkernel:lang:groovy</uri>
</import>


Cheers,
Tony
nk4um User
Posts: 24
February 4, 2010 20:54the code, and the error
StartingEndpoint.groovy, which yields StartingEndpoint.class in the base directory; obviously, the postCommission function is getting called.

import org.netkernel.module.standard.endpoint.StandardAccessorImpl
import org.netkernel.layer0.nkf.INKFRequestContext

public class StartingEndpoint extends StandardAccessorImpl {
  @Override
  protected void postCommission(INKFRequestContext context) throws Exception {
    println ''StartingEndpoint.postCommission''

    //println "context.getThisRequest(): "+context.getThisRequest() // IllegalStateException "no this request"
    println "context is $context"

    try {
      context.source(''active:groovy+operator@res%3A/web/courtResults.groovy'')
    }
    catch (Exception ex) {
      println ''Exception caught.''
      println ex
    }
   
    //Class.forName(''courtResultCache'') // no go
  }
}


What I''d really like to do is simply the Class.forName() that''s commented out, but for some reason that doesn''t work either.  I have no idea why not, since courtResultCache.class is in the base directory of the app, and therefore should be on the class path.

The error that appears in the log is the same, whether I catch it or not.  Below is the captured output:


StartingEndpoint.postCommission
context is NKFLifecycleEventContextImpl[ StartingEndpoint]
Exception caught.
<ex>
<ex>
  <id>org.netkernel.layer0.nkf.NKFException</id>
</ex>
<ex>
  <id>RequestFrameException</id>
  <request>SOURCE active:groovy+operator@res%3A/web/courtResults.groovy as Object</request>
</ex>
<ex>
  <id>Request Resolution Failure</id>
  <message>SOURCE active:groovy+operator@res%3A/web/courtResults.groovy as Object</message>
  <trace>
   <n>Starting search in [Caselaw eXtruded Transmogrified fields ]
    <n>No Match on [Fileset res:/caselaw/xt/index.html?]</n>
    <n>No Match on [Fileset res:/caselaw/xt/(.*\\.html)]</n>
    <n>No Match on [Fileset res:/etc/system/SimpleDynamicImportHook.xml]</n>
    <n>No Match on [MapperOverlay]</n>
    <n>No Match on [StartingEndpoint]</n>
   </n>
   <n>Descoping to [Caselaw eXtruded Transmogrified fields  (public)]
    <n>Private Filter denies request</n>
    <n>No Match on [PrivateFilterEndpoint]</n>
   </n>
   <n>Scope exhausted. No match found</n>
  </trace>
</ex>
</ex>


Thanks,
  -= miles =-
nk4um Moderator
Posts: 485
February 4, 2010 10:05
Hi Miles, if you issue that request it should work from inside the postCommission() method just like it works from inside the onSource() method or wherever you''ve previously tried it where it works - that''s the reason there is no explicit documentation about issuing requests from inside postCommission()

Give me the exception trace that you see when you issue this request and I''ll help you track it down. Any errors generate within this lifecycle method will not go to your browser because they aren''t issued as part of a browser initiated request. Rather they should appear in log if they haven''t been silently ignored in application code. Try putting a try/catch block around the request and do a toString no the exception.

Cheers, Tony
nk4um User
Posts: 24
February 4, 2010 03:11context????
So how do I issue a subrequest from here?

For example, if I issue a subrequest by saying :

context.source(''active:groovy+operator@res%3A/web/index.groovy'')

it works from another groovy page, but not here.
What do I need to do to get it to work?

I assume this is not documented anywhere (I certainly could not find it)
nk4um User
Posts: 24
January 29, 2010 23:21
thanks - I''ll give that a try.
nk4um Moderator
Posts: 485
January 28, 2010 06:02postCommission method
Hi Miles, the best way to execute a script at startup within a module is to declare an endpoint with a postCommission() method implemented. This is called one the module is started and it''s address space is available so it can be used to issue and request you like:

public class MyEndpoint extends StandardAccessorImpl
{
  @Override
  protected void postCommission(INKFRequestContext context) throws Exception
  {
  }
}


You can either issue a request within this method or put your code directly in there. Either way it will be executed every time NetKernel starts.

Cheers,
Tony
nk4um User
Posts: 24
January 26, 2010 19:16startup task
Is there a simple way to execute a script every time NK starts?  I''d like to define it at the module level if possible.

N.B.: Netkernel version 4.0.2

Thanks,
  -= miles =-