org.mmbase.module.builders.vwms
Class EncodeCop

java.lang.Object
  |
  +--org.mmbase.module.builders.vwms.Vwm
        |
        +--org.mmbase.module.builders.vwms.EncodeCop
All Implemented Interfaces:
MMBaseObserver, java.lang.Runnable, VwmInterface, VwmProbeInterface

public class EncodeCop
extends Vwm
implements MMBaseObserver

The EncodeCop vwm observes changes on a certain type of nodes and activates services by starting EncodeHandlers for that particular node. If a certain audio file has to be ripped, then the EncodeCop is programmed to check for newly AudioPart changes of ctype 'n' where the audiopart.source is equal to the CD audiosource. If this is true then it reacts by starting the EncodeHandler for ripping CD's. The same goes for the encoding of ripped audio. For this, the EncodeCop checks for RawAudio changes of type 'c' or 'n' where the rawaudio.state is equals to 1 and where the RawAudio represents encoded audio (eg. type=Real G2). The last type of node thats being checked is the g2encoder service. Here we check if the state is waiting and its info field is empty. If this is true, we make this g2encoder available for usage by adding it to a free services list. When an EncodeHandler is created, it is added to the EncoderHandlers list. The EncodeHandlers are removed from this list when they finish or when an error occurs during handling. Recovery : When the mmbase running this EncodeCop is being reset recovery is needed. Why?, cause there could be services that are still busy or services that just signalled that they're finished. In both cases, after mmbase reboot there are no more EncodeHandlers active for those services, thus the related rawaudios representing ripped/encoded audio won't be updated anymore. Thus, after mmbase reset recovery is written for the followin 2 cases: 1) Service was busy (eg. ripping or encoding) In this case the servicebuilder state is still 'busy' and the info field should contain the 'id' tag, where the value represents the audiopart being encoded. 2) Service just finished (eg. file ripped or encoded) In this case the servicebuilder state is 'waiting' and the info field should contain the 'result' tag and the 'id' tag. When all can be found an EncodeHandler is started that will actually handle the type of recovery needed for that particular service. Finally, another recovery routine is implemented for the case that EncodeHandlers are waiting for a g2encoder to come free again, sothat it can be used for encoding. In other words, the case that audioparts still need to be encoded. If mmbase is being reset while g2encode EncodeHandlers are queued up then we lose the queue (well, actually queue=threads that are waiting to be notified). When rebooted, we look for audioparts created from a CD source whose rawaudio state is 'verzoek' (request) and format is g2. The following node changed types exist in mmbase (stored in ctype variable: passed ctype: d: node deleted c: node changed n: new node f: node field changed r: node relation changed x: some xml notify? g: ? anyone...anyone... s: ? anyone...anyone...

Version:
$Revision: 1.23 $ $Date: 2001/07/27 13:10:26 $
Author:
Daniel Ockeloen, David van Zeventer

Fields inherited from class org.mmbase.module.builders.vwms.Vwm
name, probe, sleeptime, Vwms, wvmnode
 
Constructor Summary
EncodeCop()
           
 
Method Summary
 void addService(int servicenumber)
          Adds service to the list of free services.
 boolean audiopartChanged(java.lang.String machine, java.lang.String number, java.lang.String ctype)
          Checks the audiopart ctype and source value and when ok, it creates an EncodeHandler with task 'cdrip' to rip for this new audiopart.
 boolean g2encoderChanged(java.lang.String machine, java.lang.String number, java.lang.String ctype)
          Checks if the g2encoder state is waiting and has an empty info field.
 java.lang.String getContentsOfFreeServicesList()
          Returns contents of freeservices list as a String.
 java.lang.String getRelatedMMServerName()
          Gets the first mmserver connected to this Vwm.
 boolean nodeChanged(java.lang.String machine, java.lang.String number, java.lang.String builder, java.lang.String ctype)
          Checks node changetype and buildertype to decide which type of Changed method should be called.
 boolean nodeLocalChanged(java.lang.String machine, java.lang.String number, java.lang.String builder, java.lang.String ctype)
          Called when node was changed on local mmbase, inturn this method calls nodeChanged method.
 boolean nodeRemoteChanged(java.lang.String machine, java.lang.String number, java.lang.String builder, java.lang.String ctype)
          Called when node was changed by remote mmbase, inturn this method calls nodeChanged method.
 boolean probeCall()
          Adds observers to audiopart, rawaudio and g2encoder changes.
 boolean rawaudioChanged(java.lang.String machine, java.lang.String number, java.lang.String ctype)
          Checks the rawaudio ctype and state & format value and when ok, it creates an an EncodeHandler with task 'g2encode' to encode for this rawaudio.
 boolean removeEncodeHandler(EncodeHandler eh)
          Removes EncodeHandler reference from the EncoderHandlers vector.
 boolean removeService(int servicenumber)
          Removes the first occurence of this services from the list of free services.
 int retrieveService()
          Retrieves a service from a list of free services.
 
Methods inherited from class org.mmbase.module.builders.vwms.Vwm
addClient, claim, debug, failed, getName, getVwmNode, init, parseProperties, performed, performTask, putTask, releaseClient, rollback, run, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncodeCop

public EncodeCop()
Method Detail

probeCall

public boolean probeCall()
Adds observers to audiopart, rawaudio and g2encoder changes.
Overrides:
probeCall in class Vwm
Returns:
true, always.

nodeRemoteChanged

public boolean nodeRemoteChanged(java.lang.String machine,
                                 java.lang.String number,
                                 java.lang.String builder,
                                 java.lang.String ctype)
Called when node was changed by remote mmbase, inturn this method calls nodeChanged method.
Specified by:
nodeRemoteChanged in interface MMBaseObserver
Overrides:
nodeRemoteChanged in class Vwm
Parameters:
machine - Name of the machine that changed the node.
number - object number of node who's state has been changed remotely.
builder - a String with the buildername of the node that was changed remotely.
ctype - a String with the node change type.
Returns:
result value of nodeChanged call.

nodeLocalChanged

public boolean nodeLocalChanged(java.lang.String machine,
                                java.lang.String number,
                                java.lang.String builder,
                                java.lang.String ctype)
Called when node was changed on local mmbase, inturn this method calls nodeChanged method.
Specified by:
nodeLocalChanged in interface MMBaseObserver
Overrides:
nodeLocalChanged in class Vwm
Parameters:
machine - Name of the machine that changed the node.
number - object number of node who's state has been changed.
builder - a String with the buildername of the node that was changed.
ctype - a String with the node change type.
Returns:
result value of nodeChanged call.

nodeChanged

public boolean nodeChanged(java.lang.String machine,
                           java.lang.String number,
                           java.lang.String builder,
                           java.lang.String ctype)
Checks node changetype and buildertype to decide which type of Changed method should be called.
Parameters:
machine - Name of the machine that changed the node.
number - object number of node who's state has been changed.
builder - a String with the buildername of the node that was changed.
ctype - a String with the node change type.
Returns:
true, always.

audiopartChanged

public boolean audiopartChanged(java.lang.String machine,
                                java.lang.String number,
                                java.lang.String ctype)
Checks the audiopart ctype and source value and when ok, it creates an EncodeHandler with task 'cdrip' to rip for this new audiopart.
Parameters:
machine - Name of the machine that changed the node.
number - - a String containing the object nr of this audioparts node.
ctype - - a String with the node changed type.
number -  
Returns:
false when we can't the builder to get & check the audiopart, otherwise true .

rawaudioChanged

public boolean rawaudioChanged(java.lang.String machine,
                               java.lang.String number,
                               java.lang.String ctype)
Checks the rawaudio ctype and state & format value and when ok, it creates an an EncodeHandler with task 'g2encode' to encode for this rawaudio.
Parameters:
machine - Name of the machine that changed the node.
number - - a String containing the object nr of this rawaudios node.
ctype - - a String with the node changed type.
Returns:
false when we can't the builder to get & check the rawaudio, otherwise true.

g2encoderChanged

public boolean g2encoderChanged(java.lang.String machine,
                                java.lang.String number,
                                java.lang.String ctype)
Checks if the g2encoder state is waiting and has an empty info field. If this is true that the g2encoder is added made avaiable again by adding it to the freeservices list.
Parameters:
machine - Name of the machine that changed the node.
number - - a String containing the object nr of this g2encoders node.
ctype - - a String with the node changed type.
Returns:
false when we can't the builder or get & check the g2encoder, otherwise true.

removeEncodeHandler

public boolean removeEncodeHandler(EncodeHandler eh)
Removes EncodeHandler reference from the EncoderHandlers vector.
Parameters:
h - EncodeHandlers reference.
Returns:
a boolean result of the Vector remove.

getRelatedMMServerName

public java.lang.String getRelatedMMServerName()
Gets the first mmserver connected to this Vwm.
Returns:
mmservername or null if it can't be found.

retrieveService

public int retrieveService()
Retrieves a service from a list of free services. If there aren't any, we wait until we are notified that there is one available, which will then be retrieved.
Returns:
a free service.

addService

public void addService(int servicenumber)
Adds service to the list of free services.
Parameters:
servicenumber - that is added.
Returns:
true if service was deleted, false if service couldn't be found.

removeService

public boolean removeService(int servicenumber)
Removes the first occurence of this services from the list of free services. This situaion occurs when servicenode is deleted by someone.
Parameters:
servicenumber - that has to be removed.
Returns:
true if service was deleted, false if service couldn't be found.

getContentsOfFreeServicesList

public java.lang.String getContentsOfFreeServicesList()
Returns contents of freeservices list as a String.
Returns:
contents of freeservices list as a String.


MMBase build 1.6.5.20030923