Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * IronJacamar, a Java EE Connector Architecture implementation
   * Copyright 2012, Red Hat Inc, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.jca.core.workmanager;
 
 
 
 
The distributed work manager implementation.

Author(s):
Jesper Pedersen
 
 {
   
The logger
 
    private static CoreLogger log = Logger.getMessageLogger(CoreLogger.class,
                                                            DistributedWorkManagerImpl.class.getName());

   
Whether trace is enabled
 
    private static boolean trace = .isTraceEnabled();

   
The bundle
 
    private static CoreBundle bundle = Messages.getBundle(CoreBundle.class);

   
Policy
 
    private Policy policy;

   
Selector
 
    private Selector selector;

   
Transport
 
    private Transport transport;

   
Notification listeners
 
    private Collection<NotificationListenerlisteners;

   
Distributed statistics enabled
 
    private boolean distributedStatisticsEnabled;

   
Distributed statistics
 
Should doWork be enabled for distribution
 
    private boolean doWorkDistributionEnabled;

   
Should startWork be enabled for distribution
 
    private boolean startWorkDistributionEnabled;

   
Should scheduleWork be enabled for distribution
 
    private boolean scheduleWorkDistributionEnabled;

   
Local address
 
    private Address localAddress;

   
Constructor
 
    {
       super();
      this. = null;
      this. = null;
      this. = null;
      this. = Collections.synchronizedList(new ArrayList<NotificationListener>(3));
      this. = true;
      this. = null;
      this. = true;
      this. = true;
      this. = true;
      this. = null;
   }

   
   public Policy getPolicy()
   {
      return ;
   }

   
   public synchronized void setPolicy(Policy v)
   {
      if ( != null)
      {
         if ( instanceof NotificationListener)
            .remove((NotificationListener));
      }
       = v;
      if ( != null)
      {
         if ( instanceof NotificationListener)
            .add((NotificationListener));
      }
   }

   
   public Selector getSelector()
   {
      return ;
   }

   
   public synchronized void setSelector(Selector v)
   {
      if ( != null)
      {
         if ( instanceof NotificationListener)
      }
       = v;
      if ( != null)
      {
         if ( instanceof NotificationListener)
            .add((NotificationListener));
      }
   }

   
   public Transport getTransport()
   {
      return ;
   }

   
   public synchronized void setTransport(Transport v)
   {
      if ( != null)
      {
         if ( instanceof NotificationListener)
         removeDistributedStatistics();
      }
       = v;
      if ( != null)
      {
         if ( instanceof NotificationListener)
            .add((NotificationListener));
         initDistributedStatistics();
      }
   }

   
   public boolean isDistributedStatisticsEnabled()
   {
      return ;
   }

   
   public void setDistributedStatisticsEnabled(boolean v)
   {
   }

   
   {
      return ;
   }

   
Set the listeners

Parameters:
v The value
   {
       = v;
   }

   
   public void setDoWorkDistributionEnabled(boolean v)
   {
       = v;
   }

   
   public boolean isDoWorkDistributionEnabled()
   {
      return ;
   }

   
   public void setStartWorkDistributionEnabled(boolean v)
   {
   }

   
   public boolean isStartWorkDistributionEnabled()
   {
      return ;
   }

   
   public void setScheduleWorkDistributionEnabled(boolean v)
   {
   }

   
   public boolean isScheduleWorkDistributionEnabled()
   {
   }

   
   public void localDoWork(Work workthrows WorkException
   {
      if ( != null)
      {
         checkTransport();
         if (getLongRunningThreadPool() != null && WorkManagerUtil.isLongRunning(work))
         {
                                            getLongRunningThreadPool().getNumberOfFreeThreads() - 1);
         }
         else
         {
                                             getShortRunningThreadPool().getNumberOfFreeThreads() - 1);
         }
         WorkEventListener wel = new WorkEventListener(WorkManagerUtil.isLongRunning(work),
                                                       getShortRunningThreadPool(),
                                                       getLongRunningThreadPool(),
                                                       getLocalAddress(),
                                                       );
         super.doWork(work.nullwel);
      }
      else
      {
         super.doWork(work);
      }
   }

   
   public void localScheduleWork(Work workthrows WorkException
   {
      if ( != null)
      {
         checkTransport();
         if (getLongRunningThreadPool() != null && WorkManagerUtil.isLongRunning(work))
         {
                                            getLongRunningThreadPool().getNumberOfFreeThreads() - 1);
         }
         else
         {
                                             getShortRunningThreadPool().getNumberOfFreeThreads() - 1);
         }
         WorkEventListener wel = new WorkEventListener(WorkManagerUtil.isLongRunning(work),
                                                       getShortRunningThreadPool(),
                                                       getLongRunningThreadPool(),
                                                       getLocalAddress(),
                                                       );
         super.scheduleWork(work.nullwel);
      }
      else
      {
         super.scheduleWork(work);
      }
   }

   
   public long localStartWork(Work workthrows WorkException
   {
      if ( != null)
      {
         checkTransport();
         if (getLongRunningThreadPool() != null && WorkManagerUtil.isLongRunning(work))
         {
                                            getLongRunningThreadPool().getNumberOfFreeThreads() - 1);
         }
         else
         {
                                             getShortRunningThreadPool().getNumberOfFreeThreads() - 1);
         }
         WorkEventListener wel = new WorkEventListener(WorkManagerUtil.isLongRunning(work),
                                                       getShortRunningThreadPool(),
                                                       getLongRunningThreadPool(),
                                                       getLocalAddress(),
                                                       );
         return super.startWork(work.nullwel);
      }
      else
      {
         return super.startWork(work);
      }
   }

   
   public void doWork(Work workthrows WorkException
   {
      if ( == null ||  == null ||  == null ||
          work == null || !(work instanceof DistributableWork) || !)
      {
         localDoWork(work);
      }
      else
      {
         doFirstChecks(work.null);
         checkTransport();
         DistributableWork dw = (DistributableWork)work;
         boolean executed = false;
         if (.shouldDistribute(thisdw))
         {
            Address dwmAddress = .selectDistributedWorkManager(getLocalAddress(), dw);
            if (dwmAddress != null && !getLocalAddress().equals(dwmAddress))
            {
               .doWork(dwmAddressdw);
               executed = true;
            }
         }
         if (!executed)
         {
            localDoWork(work);
         }
      }
   }

   
   public long startWork(Work workthrows WorkException
   {
      if ( == null ||  == null ||  == null ||
          work == null || !(work instanceof DistributableWork) || !)
      {
         return localStartWork(work);
      }
      else
      {
         doFirstChecks(work.null);
         checkTransport();
         DistributableWork dw = (DistributableWork)work;
         if (.shouldDistribute(thisdw))
         {
            Address dwmAddress = .selectDistributedWorkManager(getLocalAddress(), dw);
            if (dwmAddress != null && !getLocalAddress().equals(dwmAddress))
            {
               return .startWork(dwmAddressdw);
            }
         }
         return localStartWork(work);
      }
   }

   
   public void scheduleWork(Work workthrows WorkException
   {
      if ( == null ||  == null ||  == null ||
          work == null || !(work instanceof DistributableWork) || !)
      {
         localScheduleWork(work);
      }
      else
      {
         doFirstChecks(work.null);
         checkTransport();
         DistributableWork dw = (DistributableWork)work;
         boolean executed = false;
         if (.shouldDistribute(thisdw))
         {
            Address dwmAddress = .selectDistributedWorkManager(getLocalAddress(), dw);
            if (dwmAddress != null && !getLocalAddress().equals(dwmAddress))
            {
               .scheduleWork(dwmAddressdw);
               executed = true;
            }
         }
         if (!executed)
         {
            localScheduleWork(work);
         }
      }
   }

   
Check the transport

Throws:
javax.resource.spi.work.WorkException In case of an error
   private void checkTransport() throws WorkException
   {
      if (!.isInitialized())
      {
         try
         {
            .initialize();
            initialize();
         }
         catch (Throwable t)
         {
            WorkException we = new WorkException("Exception during transport initialization");
            we.initCause(t);
            throw we;
         }
      }
   }

   
   {
      return ;
   }

   
Set the distributed statistics

Parameters:
v The value
   {
       = v;
   }

   
Init distributed statistics
   private synchronized void initDistributedStatistics()
   {
      if ( == null)
      {
      }
   }

   
Remove distributed statistics
   private synchronized void removeDistributedStatistics()
   {
      if ( != null)
      {
         .setTransport(null);
          = null;
      }
   }

   
   protected void deltaDoWorkAccepted()
   {
      if ()
         .trace("deltaDoWorkAccepted");
      super.deltaDoWorkAccepted();
      if ( &&  != null &&  != null)
      {
         try
         {
            checkTransport();
         }
         catch (WorkException we)
         {
            .debugf("deltaDoWorkAccepted: %s"we.getMessage(), we);
         }
      }
   }

   
   protected void deltaDoWorkRejected()
   {
      if ()
         .trace("deltaDoWorkRejected");
      super.deltaDoWorkRejected();
      if ( &&  != null &&  != null)
      {
         try
         {
            checkTransport();
         }
         catch (WorkException we)
         {
            .debugf("deltaDoWorkRejected: %s"we.getMessage(), we);
         }
      }
   }

   
   protected void deltaStartWorkAccepted()
   {
      if ()
         .trace("deltaStartWorkAccepted");
      super.deltaStartWorkAccepted();
      if ( &&  != null &&  != null)
      {
         try
         {
            checkTransport();
         }
         catch (WorkException we)
         {
            .debugf("deltaStartWorkAccepted: %s"we.getMessage(), we);
         }
      }
   }

   
   protected void deltaStartWorkRejected()
   {
      if ()
         .trace("deltaStartWorkRejected");
      super.deltaStartWorkRejected();
      if ( &&  != null &&  != null)
      {
         try
         {
            checkTransport();
         }
         catch (WorkException we)
         {
            .debugf("deltaStartWorkRejected: %s"we.getMessage(), we);
         }
      }
   }

   
   protected void deltaScheduleWorkAccepted()
   {
      if ()
         .trace("deltaScheduleWorkAccepted");
      super.deltaScheduleWorkAccepted();
      if ( &&  != null &&  != null)
      {
         try
         {
            checkTransport();
         }
         catch (WorkException we)
         {
            .debugf("deltaScheduleWorkAccepted: %s"we.getMessage(), we);
         }
      }
   }

   
   protected void deltaScheduleWorkRejected()
   {
      if ()
         .trace("deltaScheduleWorkRejected");
      super.deltaScheduleWorkRejected();
      if ( &&  != null &&  != null)
      {
         try
         {
            checkTransport();
         }
         catch (WorkException we)
         {
            .debugf("deltaScheduleWorkRejected: %s"we.getMessage(), we);
         }
      }
   }

   
   protected void deltaWorkSuccessful()
   {
      if ()
         .trace("deltaWorkSuccessful");
      super.deltaWorkSuccessful();
      if ( &&  != null &&  != null)
      {
         try
         {
            checkTransport();
         }
         catch (WorkException we)
         {
            .debugf("deltaWorkSuccessful: %s"we.getMessage(), we);
         }
      }
   }

   
   protected void deltaWorkFailed()
   {
      if ()
         .trace("deltaWorkFailed");
      super.deltaWorkFailed();
      if ( &&  != null &&  != null)
      {
         try
         {
            checkTransport();
         }
         catch (WorkException we)
         {
            .debugf("deltaWorkFailed: %s"we.getMessage(), we);
         }
      }
   }

   
Get local address

Returns:
The value
   {
      if ( == null)
          = new Address(getId(), getName(),  != null ? .getId() : null);
      return ;
   }

   
Initialize
   public void initialize()
   {
      if ( != null)
      {
      }
   }

   
Clone the WorkManager implementation

Returns:
A copy of the implementation
Throws:
java.lang.CloneNotSupportedException Thrown if the copy operation isn't supported
   {
      wm.setPolicy(getPolicy());
      wm.setSelector(getSelector());
      wm.setTransport(getTransport());
      wm.setDistributedStatistics(dwmsi);
      
      if (getPolicy() != null && getPolicy() instanceof NotificationListener)
         wm.listeners.add((NotificationListener)getPolicy());
      if (getSelector() != null && getSelector() instanceof NotificationListener)
         wm.listeners.add((NotificationListener)getSelector());
      if (getTransport() != null && getTransport() instanceof NotificationListener)
         wm.listeners.add((NotificationListener)getTransport());
      wm.listeners.add((NotificationListener)dwmsi);
      return wm;
   }

   
   public void toString(StringBuilder sb)
   {
      sb.append(" policy=").append();
      sb.append(" selector=").append();
      sb.append(" transport=").append();
      sb.append(" distributedStatisticsEnabled=").append();
      sb.append(" distributedStatistics=").append();
      sb.append(" listeners=").append();
      sb.append(" doWorkDistributionEnabled=").append();
      sb.append(" startWorkDistributionEnabled=").append();
      sb.append(" scheduleWorkDistributionEnabled=").append();
   }
New to GrepCode? Check out our FAQ X