com.cosylab.jcosyne.server
Class Factorization

java.lang.Object
  extended byjavax.management.NotificationBroadcasterSupport
      extended bycom.cosylab.jcosyne.server.RemoteTask
          extended bycom.cosylab.jcosyne.server.Factorization
All Implemented Interfaces:
FactorizationMBean, javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, RemoteTaskMBean, java.lang.Runnable

public class Factorization
extends RemoteTask
implements FactorizationMBean

This is a trivial implementation of the FactorizationMBean interface which uses naive brute search-for-factors algorithm. It contains delay loops on purpose so that the execution progress can be observed in JMXAdministrator GUI. This example is used in JCosyne tutorial.

Author:
Gasper Tkacik (gasper.tkacik@cosylab.com)
See Also:
FactorizationExample, JMXAdministrator

Field Summary
 
Fields inherited from class com.cosylab.jcosyne.server.RemoteTask
log, name, running, sequence, SERVER_DELEGATE, serverRef, suspended
 
Constructor Summary
Factorization()
           
 
Method Summary
 long[] getFactors()
          Returns a list of factors of LongNumber calculated up to now.
 long getLongNumber()
          Returns the number that will be factorized, or 0 if such number has not yet been set.
protected  void internalInitialize()
          Creates internal data structures.
 boolean isReadyToRun()
          Checks if the LongNumber obeys factorization constraints.
 void run()
          Implements brute force factorization.
 void setLongNumber(long number)
          Sets the number to factorize.
 
Methods inherited from class com.cosylab.jcosyne.server.RemoteTask
checkState, copyStateFrom, copyStateFrom, executeScript, getInputResource, getLastScriptResult, getName, getOutputResource, getPostExecutionScript, getPostInitializactionScript, getProgress, getSequence, getState, initialize, isAborting, isFinished, isInitialized, isRunning, isSuspended, loadMatrix, loadMatrix, notifyAttributeChange, notifyExecutionStarts, notifyExecutionStops, postDeregister, postRegister, preDeregister, preRegister, saveMatrix, setFinished, setPostExecutionScript, setPostInitializationScript, setProgress, setRunning, setSuspended
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.cosylab.jcosyne.server.RemoteTaskMBean
copyStateFrom, copyStateFrom, equals, executeScript, getLastScriptResult, getName, getPostExecutionScript, getPostInitializactionScript, getProgress, getState, hashCode, initialize, isFinished, isInitialized, isRunning, isSuspended, setPostExecutionScript, setPostInitializationScript, setRunning, setSuspended
 

Constructor Detail

Factorization

public Factorization()
Method Detail

getFactors

public long[] getFactors()
Returns a list of factors of LongNumber calculated up to now.

Specified by:
getFactors in interface FactorizationMBean
Returns:
a list of factors, null if calculation has not yet begun

getLongNumber

public long getLongNumber()
Returns the number that will be factorized, or 0 if such number has not yet been set.

Specified by:
getLongNumber in interface FactorizationMBean
Returns:
number to factorize

setLongNumber

public void setLongNumber(long number)
Sets the number to factorize. Must be larger than 1.

Specified by:
setLongNumber in interface FactorizationMBean
Parameters:
number - the number to factorize

isReadyToRun

public boolean isReadyToRun()
Checks if the LongNumber obeys factorization constraints.

Specified by:
isReadyToRun in interface RemoteTaskMBean
Returns:
true iff the number is greater than 1

run

public void run()
Implements brute force factorization. Emits Factors attribute change notifications.

Specified by:
run in interface java.lang.Runnable

internalInitialize

protected void internalInitialize()
Creates internal data structures.

Specified by:
internalInitialize in class RemoteTask
See Also:
RemoteTask.initialize()