пятница, 8 марта 2013 г.

Event Waiter

Needed a possibility to notify a thread about event occurred in anothre thread. Originally other attemps were made to organize the necessary approach inside that threads but then idea came up to use a separate object for this kind of synchronization and it finally came out as pretty intelegent light easy to read approach so good that I wanted to share it with you.

/**
 * Event Waiter object is to synchronize one or several threads with a thread-event originator</br>
 * Thread safe.</br>
 * Actors: event originator thread and one or more event waiter thread(s)</br>
 * Event Waiter thread(s) must call {@link #waitForEvent()} to wait for the Event to occur</br>
 * Event Originator thread must call {@link #eventOccurred()} to notify that the Event has been occurred</br>
 * If the Event has been occurred waiter thread(s) are not blocked on {@link #waitForEvent()} call</br>
 * If the Event has not been occurred yet waiter thread(s) are blocked on {@link #waitForEvent()} call until the Event has occurred</br>
 
 @author vtkachenko
 *
 */
public class EventWaiter {

  private boolean eventOccurred = false;

  /**
   * Once the event has been occurred this method should be called to notify that
   */
  public synchronized void eventOccurred() {
    eventOccurred = true;
    notifyAll();
  }

  /**
   * Method to wait for the event to occur
   @throws InterruptedException
   */
  public synchronized void waitForEvent() throws InterruptedException {
    if (!eventOccurred) {
      wait();
    }
  }
}

And usage example.

public class EventWaiterTest {
  
  private static void waitedFirstTest() {
    
    System.out.println("waitedFirstTest begin");
    
    final EventWaiter eventWaiter = new EventWaiter();
    
    Thread threadWithEvent = new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          Thread.sleep(1000);
        catch (InterruptedException e) {
          e.printStackTrace();
        }

        System.out.println("occurring the event...");
        eventWaiter.eventOccurred();
      }
    });
    threadWithEvent.start();
    
    try {
      System.out.println("waiting for the event...");
      eventWaiter.waitForEvent();
      System.out.println("event occurred");
    catch (InterruptedException e) {
      e.printStackTrace();
    }
    
    System.out.println("waitedFirstTest end");
  }
  
  private static void waitedLastTest() {
    
    System.out.println("waitedLastTest begin");
    
    final EventWaiter eventWaiter = new EventWaiter();
    
    Thread threadWithEvent = new Thread(new Runnable() {
      @Override
      public void run() {
        System.out.println("occurring the event...");
        eventWaiter.eventOccurred();
      }
    });
    threadWithEvent.start();

    try {
      Thread.sleep(1000);
    catch (InterruptedException e) {
      e.printStackTrace();
    }
    
    try {
      System.out.println("waiting for the event...");
      eventWaiter.waitForEvent();
      System.out.println("event occurred");
    catch (InterruptedException e) {
      e.printStackTrace();
    }
    
    System.out.println("waitedLastTest end");
  }

  /**
   @param args
   */
  public static void main(String[] args) {
    waitedFirstTest();
    waitedLastTest();
  }

}


Java HTML generated using Java2html

понедельник, 16 июля 2012 г.

Simple value assignment in BPEL

I've spent a lot of time on a problem when we need to assign just simple value to the tag body which has some attributes already assigned before. E.g. we have some variable varOut which contains the following structure:

<complexStructure>
  <complexValue someAttr="someAttrValue"></complexValue>
</complexStructure>

To assign some value from the variable varWithSimpleValue to the complexValue tag body now we might want to make a following copy procedure:

<assign name="someName">
  <copy>
    <from variable="varWithSimpleValue"/>
    <to variable="varOut" query="/complexStructure/complexValue"/>
  </copy>
</assign>

But BPEL treats source anyway as a complex structure regardles which type is used to define it, let it be even xsd:string and as a result of this operation the whole complex destination (complexValue with its children which are its attributes for the given example) is replaced thus someAttr will be lost. To solve the problem we can use string function which converts object to simple value and have a copy made like this:

<assign name="someName">
  <copy>
    <from expression="string(bpws:getVariableData(varWithSimpleValue))"/>
    <to variable="varOut" query="/complexStructure/complexValue"/>
  </copy>
</assign>

And better and more logical solution is to use text function for the destination to specify that we are selecting complexValue's simple text content not the whole structure:

<assign name="someName">
  <copy>
    <from variable="varWithSimpleValue"/>
    <to variable="varOut" query="/complexStructure/complexValue/text()"/>
  </copy>
</assign>

Originally the problem appeared with JBPM 3.2 but I believe other BPEL implementation should behave similarly.

вторник, 21 февраля 2012 г.

Our company Serena is IT Innovator of the year!

Yahoo!!!

The company I'm currently working in, Serena Software, is the Pink Elephant 2011 Innovator of the Year!!!
Here is our baby :)

Another news about that on PR-Web

пятница, 13 января 2012 г.

Deadline

Dedicated to IT... What does deadline mean for us :)

воскресенье, 4 декабря 2011 г.

9 simple rules to behave in IT team

Really really great rules to behave properly in IT team! Thanks to the "9 Things That Motivate Employees More Than Money" article by Ilya Posin. Checked on practice :) Do you also believe we should read and follow? ;)
Особенно полезна тем, кто работает в связке с зарубежной командой, что бы учесть бо́льшую мягкость менталитета наших зарубежных коллег. К сожалению, в связи с большей грубостью нашего, я сам иногда ошибаюсь. Надо контролировать себя.

среда, 2 ноября 2011 г.

2011-11-02

Today is very interesting date.
2nd of November, 2011 in ISO 8601 format (YYYY-MM-DD) is 2011-11-02 and (YYYYMMDD) - 20111102 that has symmetrical numbers along (palindrome).

My congratulations to worldwide IT crowd with this significant date! :)

понедельник, 31 октября 2011 г.

Java developers band

Just couldn't resist sharing what I've found with esteemed IT crowd :)