Sei sulla pagina 1di 21

OTM

 Agent  &  Workflow  


Design  Pa6erns  
Ian  Lo  
Oct  27,  2014  
Introduc;on  
•  About  myself  
•  Started  out  as  a  so<ware  developer  (C,  C++,  Object  Pascal,  Java)  
•  With  BAX  Global  /  DB  Schenker  (2004)  
•  Implemented  OTM  for  mulRple  customers  in  the  following  industries:  
•  Inbound  AutomoRve  in  China  /  Thailand  /  Malaysia  
•  High-­‐Tech  parts  domesRc  distribuRon  
•  High-­‐Tech  web  store  domesRc  distribuRon  for  a  global  consumer  
hardware  giant  in  Japan  
•  DomesRc  transportaRon  in  central  China  
•  FCL  &  LCL  implementaRon  in  the  Philippines    
•  Joined  MavenWire  (2010)  
•  NAFTA  distribuRon  for  large  US  Chemical  Products  manufacturer  

2  
What  Are  Design  Pa6erns?  

•  Design  Pa\erns  are  …  formal  ways  of  documenRng  a  soluRon  to  a  design  
problem  in  a  parRcular  field  of  experRse  

Each  pa\ern  describes  a  problem  that  occurs  over  and  over  again  in  our  environment,  
and  then  describes  the  core  of  the  soluRon  to  that  problem,  in  such  a  way  that  you  can  
use  this  soluRon  a  million  Rmes  over,  without  ever  doing  it  the  same  way  twice.  
—  Christopher  Alexander  

•  Design  Pa\erns  help  …  the  designer  make  decisions  

The  usefulness  of  speaking  of  pa\erns  is  to  have  a  common  terminology  for  discussing  
the  situaRons  designers  already  see  over  and  over.  

•  Design  Pa\erns  can  …  bring  “world  peace”  

Pa\erns  are  not  the  problem.  The  problem  is  when  to  apply  them.  

http://en.wikipedia.org/wiki/Design_pattern

3  
Design  Pa6erns  In  OTM  
•  There  is  no  such  thing  as  a  “Design  Pa\ern”  in  OTM.  Is  there?  
 
We  all  use  design  pa\erns  daily,  in  our  implementaRons  and  soluRon  designs.  
Recognising  pa\erns  help  to  guide  design  decisions  and  know  what  is  feasible  
and  what  is  not.  
 
OTM  implementaRons  are  o<en  based  on  past  knowledge  and  experience.  
Design  Pa\erns  help  to  “quanRfy”  and  “qualify”  knowledge  and  experiences  –  
knowing  what  to  do  and  not  to  do.  

Highlight  2  Pa\erns  in  this  PresentaRon  


•  Singleton  (borrowed  term  from  the  GOF  Design  Pa\erns)  
•  Recursion  /  Chaining  

4  
Singleton  Pa6ern  

Business  Problem  
 
A  Forwarder  Cargo  Receipt  must  be  created  based  on  bookings.  Each  FCR  will  have  
mulRple  booking’s  informaRon  such  as  weight,  volume,  piece  count  that  needs  to  be  
rated  on  the  FCR.  
 
FCRs  can  be  created  at  customer,  shipper,  voyage,  booking  line  or  container  level  

OTM  Problem  
 
We  need  to  trigger  one  single  workflow  for  mulRple  business  objects  for  the  purpose  of  
applying  custom  logic  that  needs  to  consider  only  the  selected  specific  objects.  
 
This  workflow  has  to  execute  only  once  for  this  group  of  selected  specific  objects.  

5  
Singleton  Pa6ern  

In  so<ware  engineering,  the  singleton  pa\ern  is  a  design  pa\ern  that  restricts  the  
instanRaRon  of  a  class  to  one  object.  This  is  useful  when  exactly  one  object  is  needed  to  
coordinate  acRons  across  the  system.  
 
The  term  comes  from  the  mathemaRcal  concept  of  a  singleton.  
Wikipedia  
h\p://en.wikipedia.org/wiki/Singleton_pa\ern  

OTM  Problem  
 
We  need  to  trigger  one  single  workflow  for  mulRple  business  objects  for  the  purpose  of  
applying  custom  logic  that  needs  to  consider  only  the  selected  specific  objects.  
 
This  workflow  has  to  execute  only  once  for  this  group  of  selected  specific  objects.  

6  
Singleton  Pa6ern  

" Approach  1:  Using  Data  Queries  


 
" Implementa;on  
" IdenRfy  the  specific  business  workflow  required  and  the  primary  OTM  
business  object  
" Create  a  custom  event  that  will  be  raised  through  the  data  query  in  
Process  Management  
" Create  a  PL/SQL  stored  procedure  that  implements  your  custom  logic  
and  also  returns  1  single  GID  
Custom Event
Data  Query   Agent  

1 GID Direct SQL

Other  business  
Custom  PL/SQL  
Saved query logic  

7  
Singleton  Pa6ern  

SH_CUSTOM_SINGLETON  
Data  Query   -­‐  exec  PKG_SINGLETON.Run_Logic    

MW.S0001 – Return only first GID


MW.S0002
…..
MW.S000X

Select
Primary_GID Custom  PL  /  SQL:  PKG_SINGLETON  
From xxxx
Primary_GID   MW.S0001
-­‐  FuncRon  to  return  1  GID   MW.S0002
…..
MW.S000X
Custom_Business_Logic  
-­‐  Procedure  to  execute  custom  logic  

8  
Singleton  Pa6ern  

Advantages   Disadvantages  
Simple  to  implement,  using  OOTB   Only  works  with  Data  Query  process  
funcRonality  
Applicable  to  any  business  object  that  can   PL/SQL  executed  business  logic  –  no  ability  
be  triggered  through  Data  Query   to  trigger  subsequent  OTM  workflow  
Easy  to  troubleshoot  and  debug  
Main  logic  encapsulated  in  PL/SQL  

9  
Singleton  Pa6ern  

•  Approach  2:  UI  triggered  process  based  on  a  reuse  of  OTM  business  objects  
 
•  Implementa;on  
•  IdenRfy  an  OTM  business  object  that  OTM  has  the  ability  to  group  
mulRple  objects  with:  
•  Job  (for  Orders  /  Shipments)  
•  Shipment  Group  (Shipments)  
•  Create  an  agent  that  will  be  raised  based  on  the  Create  event  of  the  
business  object  
•  Create  a  PL/SQL  stored  procedure  to  
•  Get  the  Order  Release  IDs  /  Shipment  IDs  from  the  created  “proxy”  
object  
•  Execute  your  custom  business  logic  based  on  the  IDs  based  on  the  
created  “proxy”  object  
•  Don’t  forget  to  delete  the  original  object  as  part  of  the  cleanup!  

10  
Singleton  Pa6ern  

Advantages   Disadvantages  
Can  be  done  triggered  through  the  UI   Very  complex  logic  to  cleanup  the  “used”  
OTM  business  object  
*Limited  to  OTM  objects  (Job,  Shipment  
Group)  

*  Dependent  on  Oracle  

11  
Recursion  Pa6ern  

Business  Problem  
 
Assign  a  set  of  unique  Consignment  Note  numbers  to  each  equipment  in  a  shipment.  

OTM  Problem  
Assign  a  set  of  unique  Consignment  Note  numbers  to  each  equipment  group  in  a  
shipment  and:  
1)  For  each  equipment  group  in  the  shipment,  all  the  equipments  in  the  equipment  
group  must  have  a  modulo  11  check  digit.  The  first  equipment  has  a  unique  prefix.  
2)  All  equipments  must  be  assigned  connote  numbers  before  the  shipment  is  sent  out  
to  the  Carrier  
3)  If  there  is  any  equipment  group  not  assigned  a  connote  number,  the  operaRons  must  
be  alerted  and  the  tender  to  the  carrier  stopped.  
4)  Needs  to  use  OTM’s  BN  Number  Generator  because  of  the  need  to  maintain  Carrier  
specific  connote  ranges.  
5)  All  this  must  be  done  when  the  shipment  is  built.  
6)  And  dinner  for  5  must  be  ready  by  6  pm  everyday  :o  

12  
Recursion  Pa6ern  

Fundamental OTM challenge


•  Event driven
•  Parallel execution, multi-threaded execution of agents and workflow
•  No ability to control when each agent thread will execute and in what order
•  Events are specific to a business object (not all business object have the same
agent events)

13  
Recursion  Pa6ern  

Option 1

14  
Recursion  Pa6ern  

Option 2

15  
Recursion  Pa6ern  

Recursion  is  the  process  of  repeaRng  items  in  a  self-­‐similar  way.  The  most  common  
applicaRon  of  recursion  is  in  mathemaRcs  and  computer  science,  in  which  it  refers  to  a  
method  of  defining  funcRons  in  which  the  funcRon  being  defined  is  applied  within  its  own  
definiRon.  
 
Specifically,  this  defines  an  infinite  number  of  instances  (funcRon  values),  using  a  finite  
expression  that  for  some  instances  may  refer  to  other  instances,  but  in  such  a  way  that  no  
loop  or  infinite  chain  of  references  can  occur.    
Wikipedia  
h\p://en.wikipedia.org/wiki/Recursion  

Recursion is everywhere! J

Breakdown the problem and repeat


•  Assign the connote number (and repeat)
•  Stop when all connote numbers are complete OR if the assignment is incorrect

16  
Recursion  Pa6ern  

Triggering  Agent  

Assign  Connote   Assign  Connote   Assign  


Connote  
Event:  ASSIGN_CONNOTE   Event:  ASSIGN_CONNOTE  

IF  NOT  ALL  Connotes  Assigned  THEN  


Execute  business  logic  …  
Generate  Connote  ….  
PL  /    SQL  ….  
 
  Raise  ASSIGN_CONNOTE,  Create   Raise  ASSIGN_CONNOTE,  
  New  Process   Create  New  Process  
 
ELSE  
STOP  and  END  
END  IF  
 

•  Isn’t  this  dangerous?  


•  What  about  race  condiRons?  Deadlocks?    

17  
Recursion  Pa6ern  

•  It  depends  ….  
Agent  must  have  only  1  event  triggering  it  

Assign  Connote  
Business  logic  must  apply  only  on  data  
Event:  ASSIGN_CONNOTE   that  does  not  cause  deadlock  (e.g.  not  the  
same  Equipment  Group  ID).  
IF  NOT  ALL  Connotes  Assigned  THEN  
Execute  business  logic  …  
Generate  Connote  ….  
PL  /    SQL  ….   Must  use  Create  New  Process  so  as  not  to  
  cause  the  agent  thread  from  causing  too  
many  waits.  
  Raise  ASSIGN_CONNOTE,  Create  
  New  Process  
 
ELSE   There  must  not  be  any  agent  acRons  
STOP  and  END   beyond  this  point  –  so  as  to  prevent  any  
END  IF   accidental  deadlocks  because  other  
agents  could  be  updaRng  the  same  object  
 

18  
Recursion  Pa6ern  

•  How  is  the  performance?  

•  Planned  and  assigned  9000  connotes  to  4,584  shipments  (average  of  2  equipment  groups)  
in  19  mins  –  not  too  bad  

19  
Other  Design  Pa6erns?  

•  Pa\erns  are  based  on  your  experience  and  creaRvity  –  document  &  capture  
them  as  part  of  your  toolkit  
•  Learn  to  work  within  the  constraints  of  the  available  tools  and  funcRonaliRes  
•  Important  points  to  remember  
•  Agents  are  mulR-­‐threaded  and  hence  cannot  to  control  sequence  of  
execuRon  
•  Be  aware  of  race-­‐condiRons  &  deadlocks  
•  Avoid  using  semaphores  /  locks  to  control  agent  execuRon  –  work  with  
OTM;  not  against  J  
•  Always  check  to  ensure  performance  (get  it  right  first  then  worry  about  
performance)  
 
•  OTM  is  your  friend  …..  

20  
Thank  you  
 
ian.lo@mavenwire.com  
 

Potrebbero piacerti anche