Eugene Kuleshov's Blog
Eugene Kuleshov's Homepage
Eugene Kuleshov is an independent consultant. He has over twelve years of experience in software design and development and specializing in application security, enterprise integration (EAI) and message oriented middleware. His list of clients include large financial and insurance companies.
Meet dev2dev editor.
Posted by euxx on May 18, 2006 at 11:34 PM | Permalink
| Comments (1)
During JavaOne days I finally got a chance to meet Jon Mountjoy, the dev2dev editor and really nice guy. Jon and his colleagues from dev2dev have done great job to cover various JavaOne activities. It was my pleasure to meet you guys.
.
Executing tasks with java.util.concurrent API
Posted by euxx on May 2, 2006 at 11:09 PM | Permalink
| Comments (4)
Version 0.2 of the xcommonj-work project include implementation of ExecutorService and allows to use java.util.concurrent API introduced in Java 5 for asynchronous and parallel task execution. For compatibility with JRE 1.4 (e.g. in order to run on Weblogic 8.1) you can use
this implementation is using backport-util-concurrent package.
The good thing about java.util.concurrent is that it part of JRE and and can be used in standalone applications. This API is using new Callable interface, which is essentially serve the same function as Work interface used by WorkManager. Result is stored in instance of the Future, which is practically there same as WorkItem in WorkManager API. Here is an example from the JavaDoc:
ExecutorService executor = ...
ArchiveSearcher searcher = ...
Future future = executor.submit(new Callable() {
public String call() {
return searcher.search(target);
}
});
displayOtherThings(); // do other things while searching
try {
displayText(future.get()); // use future
} catch(ExecutionException ex) {
cleanup();
}
Unfortunately, in order to use these interfaces in J2EE environment one would have to deal with the thread management, which is prohibited by specification.
Luckily, we already had all required infrastructure as part of xcommonj-work project, which is using container-managed MDB's as a thread pool. It was really easy to implement ExecutorService on top of this infrastructure.
Assuming xcommonj-work EJB is deployed and JMS is configured as described on the project page, we can use Spring framework to retrieve required dependencies from JNDI:
<bean id="executorService"
class="org.javatx.cj.work.XWorkExecutorService">
<property name="qcf" ref="workQcf"/>
<property name="queue" ref="workQueue"/>
<property name="workHome" ref="workHome"/>
</bean>
<bean id="workQcf" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="javatx.workermdb.qcf"/>
</bean>
<bean id="workQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="javatx.workermdb.queue"/>
</bean>
<bean id="workHome" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<bean id="org.javatx.cj.work.XWorkHome.JNDI_NAME"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>
</property>
</bean>
Source code for XWorkExecutorService bean is avaialable in Subversion repository of the xcommonj-work project and can be built with Maven 2 tool.
If you can't handle long task, then break it into pieces
Posted by euxx on January 23, 2006 at 8:20 AM | Permalink
| Comments (2)
Billy Newport blogged about dealing with long running synchronous operations. Most of the post he was mussing about increasing timeouts for long running EJB calls on client on server side. That helps in some cases, but does not solve root of the problem and don't really scale for a heavy load. Then Billy suggest to use JMS for async processing and if client can't wait for JMS responses let him to pull process information. Obvious, but not much details.
It would make sense to split long-running process into smaller tasks upon activation (e.g. post a JMS message for every subtask), execute each task in a separate transaction (e.g. using MDBs), and then assemble results and send notification to the client using JMS or client callback (e.g. EJB or RMI call).
Because subtasks can be processed in parallel, and even run across multiple nodes, the above approach will scale very well. However initial subtask creation may take significant time and still run into the transaction timeout. In this case it would make sense to limit number of subtasks and post special trailer message that will create another batch of subtasks for processing. If no subtasks available the same trailer message can kick a result assembler (e.g. again implemented as an MDB) which will also run asyncronously and notify client about task completion.
Resolving WebSphereMQ reason codes out of JMS errors.
Posted by euxx on November 7, 2005 at 12:55 PM | Permalink
| Comments (1)
One who ever dealt with MQSeries knows that extracting information out of WebSphereMQ (MQSeries) exceptions is a key for understanding cause of the problem. Unfortunately, implementation of MQSeries JMS client doesn't do a good job about explaining error details and you have explicitly get it from the linked exception.
...
} catch(JMSException ex) {
Exception exx = ex.getLinkedException() != null ? ex.getLinkedException() : ex;
String msg = "JMS error: "+exx.getMessage();
logger.error(msg, exx);
...
}
But even then errors you would see in the log are quite cryptic:
com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2072
That means nothing to the most of the support stuff except maybe rare MQSeries guru who can tell meaning of these reason codes from the top of the head or at least know
where to look at in the MQSeries reference documentation. For instance the above 2072 reason code correspond to an infamous "Syncpoint support not available" (MQRC_SYNCPOINT_NOT_AVAILABLE) error that cause lot of troubles before WLS 8.1 introduced Wrapped JMS Connection Factory for the Foreign JMS providers.
It is a real time saver feature to actually resolve these error codes to more meaningful names. An obvious approach would be to grab the list of reason codes from an MQSeries manual, package it as a property file with the Java code and manually resolve the error message.
...
} catch(JMSException ex) {
Exception exx = ex.getLinkedException() != null ? ex.getLinkedException() : ex;
String msg = "JMS error: "+exx.getMessage();
if(exx instanceof MQException) {
MQException mqex = (MQException) exx;
msg += " " + MQ_REASON_CODES.get(mqex.reasonCode);
}
logger.error(msg, exx);
...
}
Unfortunately above code adds dependency on MQSeries API and also require extracting over 350 errors and then keeping them in sync with MQSeries client libraries on every upgrade.
However the good news is that in many cases it is enough to extract just a symbolic name (e.g. MQRC_SYNCPOINT_NOT_AVAILABLE for an above example, which is more or less meaningful to get an initial idea about the error before looking to the manual) and all those symbolic names actually appear as static constants in MQException class. So, I wrote a little helper to extract these names right from the exception in a reflective way, without adding dependency to MQSeries API.
/**
* Helper class to resolve MQSeries reason codes
* (c) 2005, Eugene Kuleshov. All rights reserved
*/
public class MQReasonCodeResolver {
private static final Logger logger =
Logger.getLogger(MQReasonCodeResolver.class);
public static final String MQ_EXCEPTION_CLASS =
"com.ibm.mq.MQException";
public static final String RC_FIELD_PREFIX = "MQRC_";
public static final String RC_VALUE_FIELD = "reasonCode";
/**
* Resolve reson code from MQException
*
* @param mqex MQException to resolve
* @return symbolic name for reason code from MQException
*/
public static String resolve(Exception mqex) {
Class c = mqex.getClass();
try {
Field f = c.getField(RC_VALUE_FIELD);
Object key = f.get(mqex);
Field[] fields = c.getFields();
for( int i = 0; i < fields.length; i++) {
Field ff = fields[ i];
String name = ff.getName();
if(name.startsWith(RC_FIELD_PREFIX) &&
ff.get(null).equals( key)) {
return name;
}
}
} catch( Exception ex) {
logger.warn("Unable to resolve reason code; "+ex.toString());
}
return "unknown";
}
/**
* Verify if reason code can be resolved
*
* @param mqex MQException to resolve
* @return symbolic name for reason code from MQException
*/
public static boolean canResolve(Exception exx) {
Class c = exx.getClass();
while(Exception.class.isAssignableFrom(c)) {
if(MQ_EXCEPTION_CLASS.equals(c.getName())) return true;
c = c.getSuperclass();
}
return false;
}
}
The usage is very simple:
...
} catch(JMSException ex) {
Exception exx = ex.getLinkedException() != null ? ex.getLinkedException() : ex;
String msg = "JMS error: "+exx.getMessage();
if(MQReasonCodeResolver.canResolve(exx)) {
msg += " "+MQReasonCodeResolver.resolve(exx);
}
logger.error(msg, exx);
...
}
Which would now log the following
MQJE001: Completion Code 2, Reason 2072 MQRC_SYNCPOINT_NOT_AVAILABLE
Implementing J2EE-based services for a real world.
Posted by euxx on August 12, 2005 at 9:45 AM | Permalink
| Comments (7)
Bobby Woolf posted a blog entry "How to Implement a Service in J2EE". He is suggesting to use SSB if service using synchronous transport (such as HTTP or RMI) and MDB in case if transport is asynchronous (e.g. JMS or JCA).
Part of the beauty of implementing a service as an SSB is that clients then have great flexibility to invoke it synchronously or asynchronously. I've already discussed asynchronous access using service activators for HTTP or JMS transports. Java clients of the service may wish to invoke the service synchronously, which is easy to do with an SSB--just use its local or remote home and interface. So SSBs make service invocation very flexible.
It is hard to disagree with this. Services exposed as SSB and MDB managed by J2EE application server is a really good option, because it automatically provides remoting, transactionality, security, pooling, load balancing, failover recovery, etc. to both client an service provider and especially if you can afford to use an application server there is truly no point to reinvent the wheel and spend time on reimplementing these services.
Some people don't like EJBs. Perhaps they're not using Java, they're using .NET; they'll use .NET's equivalent of an SSB. Perhaps they're using Java but not J2EE, or at least not EJBs. This principle still applies, they would just use a JavaBean/POJO. But that J2SE object would need to handle security, transactions, remoteness, pooling--pretty soon, you've reinvented EJBs, so you should just use EJBs to begin with.
So an SSB isn't the only way to implement a service in Java, but if you want to take advantage of J2EE, then an SSB is a good way to go.
Well, it had been discussed a lot some time ago when IoC containers started to became popular. This is seems too strong statement to say that POJO-based design is leaking support of security, transactions, remoteness, etc. Those are really crosscutting concerns and has very little or nothing to do with actual business logic. Moreover these separate concerns don't really require unit testing, but only integration testing.
In my opinion the much more flexible approach that benefits from both is to use EJB's only as a Service Facade for boundaries that may have remoting, transactionality, etc. and keep actual business logic implementation in POJO's driven by some IoC container. Then EJB code will look something like this (with XDoclet annotations):
private RequestProcessor requestProcessor;
/**
* @ejb.interface-method view-type = "both"
* @ejb.transaction type = "RequiresNew"
*/
public String request( String msg) {
return requestProcessor.submitSync( msg);
}
Where requestProcessor is a POJO managed by Spring. Note that code is so simple that practically require no testing at component level.
This is how service components are wired together.
Notice that POJO component can be still used outside container (e.g. in a standalone client), which is particularly handy for testing and debugging.
The above approach has several significant benefits during development. The following table provides comparison between EJB and POJO-based component development. As you can see, POJOs make testing easier and the time for the entire change/build/deploy/test/verify cycle is about 5...10+ times less in this case and allows more dynamic development process.
| -- |
EJB |
POJO |
| Change |
Force to use Component
Oriented and limited Object Oriented |
Object Oriented |
| Build |
Slow because require to build deployment
package, generate stubs
Can be optimized with proper toolset (e.g. when deploying exploded
application),
but this introduces additional risk and require additional testing for
the real deployment configuration. |
Fast, because there is no overhead to generate
stubs, etc.
|
| Deploy |
Slow in most cases because J2EE container does
lot of expensive initialization.
|
N/A |
| Startup |
Slow. J2EE application server startup takes lot
of time. |
Fast. IoC containers can use lazy initialization and load only active components.
|
| Test |
Require special approach to test local beans,
e.g. Cactus (but this usually increases build time because tests
require additional stubs). Testing of the asynchronous components such
as MDB is even more challenging.
|
Plain JUnit. Can be tested directly from the IDE and does not require to redeploy entire application to test only
changed component.
|
| Verify |
Challenging, because it is difficult to mock the dependent services and prepare preconditions for testing.
|
Very flexible. Depended services and
preconditions can be mocked or stubbed, which allows to cover more code
with less effort.
|
| Average time |
0.5-5 minutes for not very big component. |
2-10 seconds for the same component |
There are many other benefits with POJO-based implementation that I'd like to talk about in other posts.
Implementing Work Manager specification on J2EE 1.3
Posted by euxx on June 8, 2005 at 9:40 AM | Permalink
| Comments (12)
CommonJ Work Manager specification (JSR 237) allows parallel task execution in J2EE application, but this API is not supported by WebLogic 7 and 8.1 (J2EE 1.3)
Dmitri's article inspired me to implement this functionality for existing servers and this project just got approved on CodeShare and I'll commit all code there in a day or so.
When this component is deployed, J2EE application on WebLogic 8.1 can use exactly the same API as it would use on WebLogic 9 or WebSphere.
InitialContext ctx = new InitialContext();
WorkManager workManager = ( WorkManager) ctx.lookup( "org.javatx.cj.work.WorkManager");
workManager.schedule(new TestWork( "work1"));
workManager.schedule(new TestWork( "work2"));
You can subscribe to the mailing lists, drop your comments and suggestions here or in project's discussion forum.
Visualize WebLogic's config.xml
Posted by euxx on April 27, 2005 at 11:15 AM | Permalink
| Comments (3)
All configuration parameters of the WebLogic server are stored to single config.xml file saved in the domain directory. This config file is a primary source of information about all configuration parameters including JDBC connection pools, JMS, JTA, logging, clustering, deployed application, etc.
Note that reference documentation does not recommend editing config.xml directly!
The good thing about config.xml is that it can be viewed in any text editor. For example:
<?xml version="1.0" encoding="UTF-8"?>
<Domain ConfigurationVersion="8.1.3.0" Name="mydomain">
<Server ExpectedToRun="false" JMSThreadPoolSize="10"
ListenAddress="" ListenPort="7001" Name="myserver"
NativeIOEnabled="true" ReliableDeliveryPolicy="RMDefaultPolicy"
ServerVersion="8.1.3.0" StdoutDebugEnabled="true" StdoutSeverityLevel="64">
...
<JDBCConnectionPool DriverName="oracle.jdbc.driver.OracleDriver"
InitialCapacity="1" MaxCapacity="10" Name="wliBackupPool"
Password="{3DES}lU/aklIfTfKSok8gf4WpNg=="
PreparedStatementCacheSize="300"
...
From the above config fragment you can see that JDBC connection pool with name wliBackupPool is using non-XA JDBC driver oracle.jdbc.driver.OracleDriver.
Unfortunately, for a heavily customized server that has several applications deployed, config.xml could be very large and browsing it without a special tool or XML-aware editor is no fun at all. However it is still the fastest way to verify server configuration.
One of the possible solutions to this issue is to transform config.xml to more readable document. There are lot of different tools can be used to do that and most of them will require special configuration. From other hand, these days pretty much any workstation has web browser and most if not all of them can apply XSL and CSS document transformations on the fly. You can specify stylesheet location using special processing instruction in XML document and browser will use that stylesheet to transform data before rendering it on the screen. For example:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"
href="http://dev2dev.bea.com/blog/euxx/config.xsl"?>
<Domain ConfigurationVersion="8.1.3.0" Name="mydomain"?>
<Server ExpectedToRun="false" JMSThreadPoolSize="10"
...
I've prepared a simple XSL transformation that shows structure of the config.xml. After adding above instruction to config.xml it can be opened in a web browser.

Another handy thing is that for every config element there is a link to an appropriate place in the WebLogic Server Configuration Reference.
 |
 |
October 2007
| Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
| |
1 |
2 |
3 |
4 |
5 |
6 |
| 7 |
8 |
9 |
10 |
11 |
12 |
13 |
| 14 |
15 |
16 |
17 |
18 |
19 |
20 |
| 21 |
22 |
23 |
24 |
25 |
26 |
27 |
| 28 |
29 |
30 |
31 |
|
|
|
Search this blog:
Archives
May 2006
January 2006
November 2005
August 2005
June 2005
April 2005
Categories
Product: WebLogic Server
Role: Architect
Technology: Dev Toolbox
Technology: EJB
Technology: JMS
Technology: Service-oriented Architecture
Recent Entries
Meet dev2dev editor.
Executing tasks with java.util.concurrent API
If you can't handle long task, then break it into pieces
Articles
High Performance Message Processing with BMT Message-Driven Beans and Spring
Addressing the traditional MDB-based message consumption model, Dmitri
Maximovich and Eugene Kuleshov show how this scenario can be
refactored to increase performance with non-transactional message
retrieval while retaining once-and-only-once quality of service. Jan. 30, 2006 Using the Spring AOP Framework with EJB Components
EJB components can comfortably coexist with the Spring Framework. In this article, Eugene Kuleshov shows how, and demonstrates how this naturally leads to a wealth of additional functionality that can be transparently added using AOP. Dec. 19, 2005 Using and hacking Subclipse - the Subversion plugin for Eclipse
Subversion is a compelling replacement for the CVS version control system. This article shows how to access a Subversion repository (such as CodeShare) using the Subclipe Eclipse plug-in, and how to extend the plug-in itself. Nov. 30, 2005
All articles by Eugene Kuleshov »

|