Friday, February 24, 2012

Export and Import Domino Java libraries

I describe how to export Domino Java Libraries in to Eclipse Projects. Current post will show how to do backward operation  - import Eclipse project in to Domino library.  Within both way you will be able to import\export Domino java libraries in to Eclipse project.



The main reason to do it is to use Control Version on class level but java library level. This application will be very useful if you do many code in the Domino Java libraries and works in team.

Documentation

Feel free to use it

Wednesday, February 22, 2012

"Facebook shares" retrieve in a back end

Sometimes you need to get Facebook shares number of you pages in back end. I was need it for performance reason, it faster to preload this data from Facebook in to Domino document and then show it.

There are two way to do it:

FQL 


You could find examples and explanation following http://developers.facebook.com/docs/reference/fql/link_stat/.

Within FQL you could get shared statistic divided by "share", "like", "comment" and also sum of them.



Graph API


Look http://developers.facebook.com/docs/reference/api/ for"id" query.


Graph API as well as actual "like button" widget shows "total_count" number.  Some people think this is not completely correct, but Facebook developers suppose it's correct.

Example of  read shares from java under the cut

Tuesday, February 14, 2012

Concurrency Lotus Document Processing in Java

Domino have all objects synchronized within session so it does not look a good idea to do something with documents in multiple threads in Domino. Some time you need to do some on document that takes a lot of time out of Domino objects, like read some data from URL and put it to the document. Reading URL source data will take a lot of time there, so it is a good idea to do such task in multiple threads.

Take in to mind this multiple thread test on 50 documents

Only document access operations like computeWithForm:

1 thread: 110 ms
10 thread: 124 ms (looks like the same)

Document access (computeWithForm) and read source from URL:

1 thread: 14330 ms
10 thread: 2369 ms (83 % faster then one thread)

I want to present an special class for easy process documents in multiple threads. It based on ExtendedCollection and NotesExecutorService. Realization is under the cut.


Monday, February 13, 2012

How to run Domino Java agents in Multi threads

You could use ExecutorService for Domino Java for running Domino Java agents in the few threads.

There is only one attention:

You know that code will wait until agent.run() or agent.runOnServer() finish. It looks like this methods using thread.wait() for waiting the end of the task. So interrupt() in NotesExecutorService.NotesTask.stopThread() will interrupt not only the NotesTask thread itself but  agent.run() also.

If you are using ExecutorService for Domino Java for running agents then you need to run task in the synchronized method to avoid calling .stopThread() [read interrupt()] until it waits agent finishing [read agent.run() done] 

Changes under the cut

Friday, February 10, 2012

ExecutorService for Domino Java

ExecutorService is a good to use class, but it have a little problem in domino
http://lotusandjava.blogspot.com/2012/02/take-attention-on-executorservice-in.html

It's nice when company politic allow you to fix it like this
http://www-01.ibm.com/support/docview.wss?uid=swg21279509

If you are not allowed to do it, than you got a little trouble. Fortunately Java is creator friendly language, so you could do ExecutorService himself.

I did NotesExecutorService on the base of next articles:
http://tutorials.jenkov.com/java-concurrency/blocking-queues.html
http://java.dzone.com/news/java-concurrency-thread-pools

Modification NotesExecutorService for run multiple thread agents you could find following link How to run Domino Java agents in Multi threads

NotesExecutorService itself under the cut

Thursday, February 9, 2012

How To: jQuery on demand

jQuery are needs to be loaded on demand some times. There is lot of examples but I will add one more from me.

You could wrrite some functions that needs jQuery, some "function myFunctionWithjQuery(){...}", and call it as "initializeJ('myFunctionWithjQuery')".

"initializeJ" will load jQuery, after that, "myFunctionWithjQuery" will be called.

"initializeJ" under cut

Wednesday, February 8, 2012

Tuesday, February 7, 2012

How To: export Domino Java Libraries in to Eclipse Projects

Based on my previous blog post I create utility for exporting Domino Java Libraries in to Eclipse projects. It is a simple java program with command line interface




Take attention on "ExecutorService" in Domino Java

If you will use "ExecutorService" in your Domino Java code, you will need additional configure Java Security.

"shutdown" method in "ExecutorService" will throw "AccessControlException" in trival java agent.

 java.security.AccessControlException: Access denied (java.lang.RuntimePermission modifyThread)
    at java.security.AccessControlException.<init>(AccessControlException.java:62)
    at java.security.AccessController.checkPermission(AccessController.java:68)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:544)
    at java.util.concurrent.ThreadPoolExecutor.shutdown(ThreadPoolExecutor.java:1105)


Yes, this is not a bug but this turn my mind in to stat like this is bug.

Here the way to resolve
http://www-01.ibm.com/support/docview.wss?uid=swg21279509

Or you could create your own executor like NotesExecutorService

Saturday, February 4, 2012

How To: unmap MappedByteBuffer

There is an issue in the JVM  "Add unmap method to MappedByteBuffer"

We got this bug in the How To: extract some text nodes from DXL in to files. File could not be deleted in the current program flow - that is the effect of this bug.

There is some solution, I will show example under cut

Ho To: easy Java agent development

Widely spread practice to write java code in the agent. Some coll guys will say, you need to write in library and append library to the agent.

I want to show you a more clear scheme:
So you will be able to easy manage code of all agent in one place.

Mode explanation under cut

Friday, February 3, 2012

How To: extract attachment from DXL (XML) in to the file in Java

I will show how to extract some raw data from DXL in to the file.

We need two things:

1. Code for extracting DXL
2. Some Utility to decode Base64

".jar" files from the Java Libraries will be extracted in our example

How To: create project for Lotus Notes\Domino development in Eclipse

I will show how you could create an Eclipse project configured for work with Lotus Notes\Domino.

This will be a simple java class as always.

First of all you need to do one thing out of java programming - add Domino JRE to Eclipse. You could use any JRE you want, but I prefer to use Domino or Notes JRE because it's "native" for our future code. So let's add it and call it "Domino":


You also will need one more information for our program - path to the Notes.jar like "C:\Program Files (x86)\IBM\Lotus\Notes\jvm\lib\ext"

Having JRE in Eclipse and Path to Notes.jar you could run your program (with my class).

And ... you could just import ready Domino Java Project in to Eclipse:


Now you could easily work with project - it is configured for work with  Lotus Notes\Domino


look message if interested in implementing

How To: write string in to file in one line of code

There is many examples how to do it, I propose you to add one tiny method to your code and forget.

How To: wrapp StringBuffer.append to print each "append" in new line

All of you know fine StringBuilder (StringBuffer) classes. Time to time you need to out multilines text and must code something like

Thursday, February 2, 2012

How To: simple Log in Java

If you need log in your application, you could find a lot of implementation in the internet. The best one is Apache log4j

But in the case of simple application I prefer to use a tiny Log class:

New subscription for Domino developers on StackOverflow

Feel free to engage in to xPages thread on the StackOverflow

How To: extract some text nodes from DXL in to files

One more post about processing DXL.

I will show how to extract text nodes from the Database DXL. We will use previous code How To: export DXL in Java and How To: parse DXL in Java

Let's extract Java Libraries from our datbase DXL, like it does Source Control Enablement for Designer

How To: clean directory in Java

There are tons of file utils on the web. The best one is File Utilities in Apache commons IO.

Any way, if you need just deleting directory with sub-directories or just clean directory form all files and sub-directories, then look at my tiny example

How To: run Domino agent outside from Lotus Notes client

This is simple with the help of Java API

How To: parse DXL in Java

How to export database in to DXL I described in How To: export DXL in Java

To do something with resulting DXL we need to find a way to easy get anything we want from the DXL. I will show how to do it with DOM parser. This is easy as always.

XPages does not run in NTF

I got a problem: XPages could not be opened from .NTF in the client

"XPages cannot process the application launch page: notes:///discussion8.ntf/allDocuments.xsp?OpenXPage"

I suppose this could be because of .NTF could not be opened on the web also, so Lotus does not run HTTP to process XPage for the client.

So .NTF becomes useless for development because of you could not test what you are doing immediately.

Wednesday, February 1, 2012

How To: read image from URL in Java

It's fairly easy.
Next example shows how to read an image and show it in a little java window, as well as read as image and store it in to the file

How To: parse HTML in Java

If you want to parse HTML in java, you could find a lot of different libraries from google search. I am preffer jsoup. The main reason is that this is pretty simple and easy to work with jsoup.
And yes, it is free to use.
If you like that code, try it: http://jsoup.org/

How To: read HTML source from URL in Java

HTML source could be read easily like
HtmlRemoteSource class

How To: detect operation system in Java

There is well known way to detect operation system
Work with strict type is much better in my opinion. Something like this:
It will allow to do strict switch:
The class itself