cancel
Showing results for 
Search instead for 
Did you mean: 

creating KM Service

Former Member
0 Kudos

Hi all,

I'm trying to implement an own KM service in EP6 SP2.

It should repeatedly (about every 10 minutes) search for documents of some property in KM repository defined and then copy them into specified location/folder.

Now the service works fine, but some problems occurs when the EP is starting (<b>after EP restart the service hangs the portal</b>).

now I'll try to show some code:

<i>

public class MyService implements IMyService, Runnable {

.

.

.

try {

IResourceFactory m_Factory = ResourceFactory.getInstance();

if (m_Factory != null) {

IResourceContext context = m_Factory.getServiceContext("our_service_user");

if (context != null) {

RID aRid = RID.getRID(rootDir);

ICollection aCollection =(ICollection) m_Factory.getResource(aRid, context);

.

.

.

} catch (ResourceException e) {

...

</i>

When I deploy the service to the running portal it works fine. But when the portal is starting the service hangs at this line:

<i>IResourceContext context = m_Factory.getServiceContext("our_service_user");</i>

Maybe the KM is not initialized till now (it initializes when the user first uses a KM iview (com.sap.km.cm.navigation, ...)).

Does anybody know how to initialize the KM from the API?

Any hints?

Romano

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Romano,

I'm trying to do something similar - how have you managed to get the service to run every 10 minutes? Did you use the Scheduler service or are you using a timer?

Good luck,

Rashad

Former Member
0 Kudos

Hi,

this is the way I did it:

<i>

public void run() {

while (true) {

try {

Thread.sleep(600000L);

} catch (Exception ex) {

}

//... do something here...

}

}

</i>

Have a look at the Java Development -> Documentation -> Getting started -> Portaloto Service in EP6 PDK.

Romano

Former Member
0 Kudos

Thanks Romano!

In case you haven't managed to solve your problem, I read some SAP documentation this weekend (sorry, can't remember which document!) which implies that if you do anything in the init() method of your service, there is a chance that any other services may not have been initialised yet. It is best to use the afterInit() method.

I hope this helps.

Cheers,

Rashad

Former Member
0 Kudos

Hmmm,

I'm not sure I understand.

In my service the init method looks like this:

<i> public void init(IServiceContext context) {

t = new Thread(this);

t.setDaemon(true);

t.start();

}</i>

I just start a new thread (don't ask why, but when I deploy this the "destroy" method kills the previous thread - I think - so no more than 1 instance of my service runs at one time (maybe it is not neccesary):

<i> public void destroy() {

t.stop();

t = null;

}</i>

All the process comes in the method "run".

Now I'm thinking about creating another service, which will periodically try to connect to portal to "raise" the KM and give the information about the success to my second - KM service.

So any hints will be usefull.

Romano