SlideShare uma empresa Scribd logo
1 de 20
XOOPS 2.6.0XOOPS 2.6.0
Education SeriesEducation Series
XOOPS 2.6.0XOOPS 2.6.0
Education SeriesEducation Series
Introduction toIntroduction to
Service ManagerService Manager
In XOOPS CMS EnvironmentIn XOOPS CMS Environment
Richard Griffith
XOOPS Core Team Leader
May 2014© 2014 XOOPS Foundation www.xoops.org
© 2014 XOOPS Foundation www.xoops.org
Service Management
In XOOPS 2.6.0 alpha 2, some familiar services
that were traditionally internal parts of the core
were separated into modules.
Some examples are:
avatars, comments, and notifications
© 2014 XOOPS Foundation www.xoops.org
Separated Module Benefits
The separated module approach achieves
some important benefits:
●
Modules can be updated independently.
●
Modules can have private resources, such as
templates, configurations, maintenance pages.
●
Modules can be omitted if not needed, saving
some resources.
© 2014 XOOPS Foundation www.xoops.org
Problems with Separation
There are potential benefits to separation that
were not realized:
●
The service modules were not easily replaced
with alternate implementations
●
References using hard coded module names
litter the entire system wherever a service is
needed
© 2014 XOOPS Foundation www.xoops.org
Direct Module Connection
●
Each time the service
is used, the calling
code must check to
see if module is
installed
●
Usage generally
requires intimate
knowledge of the
service internals
© 2014 XOOPS Foundation www.xoops.org
Service Manager
To achieve the full benefit of the separation,
XOOPS 2.6.0 alpha 3 introduces a Service
Manager component.
●
Services located by service name, not provider
●
Service interface established by Contract
●
Returns a standardized Response object that
includes result, status and messages
© 2014 XOOPS Foundation www.xoops.org
Service Manager Connection
●
Request is based on a well
known interface
●
Actual provider does not matter
to caller
●
No need to check for a specific
module
●
If the service is not available,
that status is returned just like
any other error condition.
© 2014 XOOPS Foundation www.xoops.org
if ($xoops->isActiveModule('notifications')) {
$notification_handler = Notifications::getInstance()->getHandlerNotification();
$notification_handler->triggerEvent('global', 0, 'category_created', $tags);
}
Code Simplification
$xoops->service('Notify')->triggerEvent('global', 0, 'category_created', $tags);
Direct Module Connection
Service Manager Connection
© 2014 XOOPS Foundation www.xoops.org
Service Manager Components
namespace XoopsCoreService;
AbstractContract.php Abstract Class Contract boilerplate
Manager.php Class Manages service providers
NullProvider.php Class Provider used when no provider is installed
Provider.php Class Basic Provider support
Response.php Class Response used by all service providers
namespace XoopsCoreServiceContract;
This namespace holds interfaces that define all named
services. For example, a contract for an 'Avatar' service
would be XoopsCoreServiceContractAvatarInterface
© 2014 XOOPS Foundation www.xoops.org
Service Provider
Any module can implement a service provider.
To provide a service, the module must respond to
a core.service.locate.name event. This is
usually accomplished using a PreloadItem.
The locate event will supply a Provider object,
and the module listener is expected to invoke the
register() method of that object with an instance of
its own provider implementation.
© 2014 XOOPS Foundation www.xoops.org
Registering a Service Provider
Avatar preload example:
/**
* listen for core.service.locate.avatar event
*
* @param Provider $provider - provider object for requested service
*
* @return void
*/
public static function eventCoreServiceLocateAvatar(Provider $provider)
{
if (is_a($provider, 'XoopsCoreServiceProvider')) {
$path = dirname(dirname(__FILE__)) . '/class/AvatarsProvider.php';
require $path;
$object = new AvatarsProvider();
$provider->register($object);
}
}
© 2014 XOOPS Foundation www.xoops.org
Service Provider Implementation
Avatar example:
use XoopsCoreServiceAbstractContract;
use XoopsCoreServiceContractAvatarInterface;
class AvatarsProvider extends AbstractContract implements AvatarInterface
{
// implementation goes here
}
© 2014 XOOPS Foundation www.xoops.org
Service Contract Example
namespace XoopsCoreServiceContract;
interface AvatarInterface
{
const MODE = XoopsCoreServiceManager::MODE_EXCLUSIVE;
/**
* @param Response $response XoopsCoreServiceResponse object
* @param mixed $userinfo XoopsUser object
*
* @return void - response->value absolute URL to avatar image
*/
public function getAvatarUrl($response, $userinfo);
/**
* @param Response $response XoopsCoreServiceResponse object
* @param mixed $userinfo XoopsUser object
*
* @return void - response->value absolute URL to edit function
*/
public function getAvatarEditUrl($response, $userinfo);
}
© 2014 XOOPS Foundation www.xoops.org
Using a Service
// get Xoops object
$xoops = Xoops::getInstance();
// get provider
$provider = $xoops->service('Avatar');
// call contract method
$response = $provider->getAvatarUrl($user);
// get value from response
$avatar = $response->getValue();
// all together
$avatar = $xoops->service('Avatar')->getAvatarUrl($user)->getValue();
© 2014 XOOPS Foundation www.xoops.org
Response Object
●
Response objects are managed automatically, so you should never need to
instantiate one.
●
Useful methods when consuming a service
– isSuccess() - true if service call was a success
– getValue() - get the value set by the call, can be any PHP type (scalar, array,
object, etc.) If no provider is available, getValue() will return NULL.
– getErrorMessage – get array of messages
●
A Response object is the first argument to all Contract methods, but never
included in the service() call
– A program calls the service manager
– The service manager:
• creates a response object
• calls the contract method
• returns the response object to the caller
© 2014 XOOPS Foundation www.xoops.org
Contract Methods and
Response Objects
The service manager handles all response
objects and calls the contract providers. To isolate
the responsibilities for the response object, it is
passed to the contract methods. As a result, the
call to the service manager and the call to the
contract implementation are different:
Service call:
$response = $xoops->service("Avatar")->getAvatarUrl($userinfo);
Contract definition:
public function getAvatarUrl($response, $userinfo);
© 2014 XOOPS Foundation www.xoops.org
Lazy Service Location
Service providers are only instantiated when explicitly
requested, and then kept for the duration of the PHP run.
A locate event is not triggered until a named service is
first requested, so if a service is not used, it has no
overhead cost.
If no providers for a service are installed, the locate
trigger has little cost, and any subsequent calls go
straight to a NullProvider that minimizes resource use.
© 2014 XOOPS Foundation www.xoops.org
Service Manager Administration
– For simple cases, just install the provider module / extension and
it will just work.
– For more complex cases use the services section in the
administration area
© 2014 XOOPS Foundation www.xoops.org
Future of Service Manager
●
User side interface to choose a specific provider for MODE_PREFERENCE, for
example:
– Editors
●
Implement MODE_MULTIPLE support, calling multiple providers in sequence. Some
possible uses are:
– Security inspections
– Spam prevention lookups
●
Complete conversions and separate additional services
– Presently only Avatar provider is implemented
– Comments and Notifications to follow
– Other possibilities
●
Mailer
●
Editors
●
Captcha
●
Image library
●
Important part of “everything is a module” strategy
20
© 2014 XOOPS Foundation www.xoops.org
If you have any suggestions,
comments or questions, please make
them known.
You can contact the author here :
richard@geekwright.com
IDEAS ? QUESTIONS ?
www.xoops.org

Mais conteúdo relacionado

Mais procurados

RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with JerseyScott Leberknight
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesGerald Villorente
 
DSpace Tutorial : Open Source Digital Library
DSpace Tutorial : Open Source Digital LibraryDSpace Tutorial : Open Source Digital Library
DSpace Tutorial : Open Source Digital Libraryrajivkumarmca
 
RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RSArun Gupta
 
Moodle 3.3 - API Change Overview #mootieuk17
Moodle 3.3 - API Change Overview #mootieuk17Moodle 3.3 - API Change Overview #mootieuk17
Moodle 3.3 - API Change Overview #mootieuk17Dan Poltawski
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With MysqlHarit Kothari
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPHP Barcelona Conference
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans Fabrizio Giudici
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 
20100622 e z_find_slides_gig_v2.1
20100622 e z_find_slides_gig_v2.120100622 e z_find_slides_gig_v2.1
20100622 e z_find_slides_gig_v2.1Gilles Guirand
 
Make your gui shine with ajax solr
Make your gui shine with ajax solrMake your gui shine with ajax solr
Make your gui shine with ajax solrlucenerevolution
 
Javase7 1641812
Javase7 1641812Javase7 1641812
Javase7 1641812Vinay H G
 

Mais procurados (20)

RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
MySQL
MySQLMySQL
MySQL
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, Terminologies
 
Introduction to DSpace
Introduction to DSpaceIntroduction to DSpace
Introduction to DSpace
 
DSpace Tutorial : Open Source Digital Library
DSpace Tutorial : Open Source Digital LibraryDSpace Tutorial : Open Source Digital Library
DSpace Tutorial : Open Source Digital Library
 
RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RS
 
Persistences
PersistencesPersistences
Persistences
 
Moodle 3.3 - API Change Overview #mootieuk17
Moodle 3.3 - API Change Overview #mootieuk17Moodle 3.3 - API Change Overview #mootieuk17
Moodle 3.3 - API Change Overview #mootieuk17
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With Mysql
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi Mensah
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
backend
backendbackend
backend
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
20100622 e z_find_slides_gig_v2.1
20100622 e z_find_slides_gig_v2.120100622 e z_find_slides_gig_v2.1
20100622 e z_find_slides_gig_v2.1
 
Drupal Modules
Drupal ModulesDrupal Modules
Drupal Modules
 
Make your gui shine with ajax solr
Make your gui shine with ajax solrMake your gui shine with ajax solr
Make your gui shine with ajax solr
 
Javase7 1641812
Javase7 1641812Javase7 1641812
Javase7 1641812
 

Semelhante a XOOPS 2.6.0 Service Manager

What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
Drupal 7 module development
Drupal 7 module developmentDrupal 7 module development
Drupal 7 module developmentAdam Kalsey
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...King Foo
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 3camp
 
Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009hugowetterberg
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in reactBOSC Tech Labs
 
Symfony and Drupal 8
Symfony and Drupal 8Symfony and Drupal 8
Symfony and Drupal 8Kunal Kursija
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8Alexei Gorobets
 
Drupal 8 meets to symphony
Drupal 8 meets to symphonyDrupal 8 meets to symphony
Drupal 8 meets to symphonyBrahampal Singh
 
Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)Eugenio Minardi
 
Angular presentation
Angular presentationAngular presentation
Angular presentationMatus Szabo
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin GeneratorJohn Cleveley
 

Semelhante a XOOPS 2.6.0 Service Manager (20)

What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Drupal 7 module development
Drupal 7 module developmentDrupal 7 module development
Drupal 7 module development
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2
 
Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
Symfony and Drupal 8
Symfony and Drupal 8Symfony and Drupal 8
Symfony and Drupal 8
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
 
Drupal 8 meets to symphony
Drupal 8 meets to symphonyDrupal 8 meets to symphony
Drupal 8 meets to symphony
 
Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 

Último

Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 

Último (20)

Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 

XOOPS 2.6.0 Service Manager

  • 1. XOOPS 2.6.0XOOPS 2.6.0 Education SeriesEducation Series XOOPS 2.6.0XOOPS 2.6.0 Education SeriesEducation Series Introduction toIntroduction to Service ManagerService Manager In XOOPS CMS EnvironmentIn XOOPS CMS Environment Richard Griffith XOOPS Core Team Leader May 2014© 2014 XOOPS Foundation www.xoops.org
  • 2. © 2014 XOOPS Foundation www.xoops.org Service Management In XOOPS 2.6.0 alpha 2, some familiar services that were traditionally internal parts of the core were separated into modules. Some examples are: avatars, comments, and notifications
  • 3. © 2014 XOOPS Foundation www.xoops.org Separated Module Benefits The separated module approach achieves some important benefits: ● Modules can be updated independently. ● Modules can have private resources, such as templates, configurations, maintenance pages. ● Modules can be omitted if not needed, saving some resources.
  • 4. © 2014 XOOPS Foundation www.xoops.org Problems with Separation There are potential benefits to separation that were not realized: ● The service modules were not easily replaced with alternate implementations ● References using hard coded module names litter the entire system wherever a service is needed
  • 5. © 2014 XOOPS Foundation www.xoops.org Direct Module Connection ● Each time the service is used, the calling code must check to see if module is installed ● Usage generally requires intimate knowledge of the service internals
  • 6. © 2014 XOOPS Foundation www.xoops.org Service Manager To achieve the full benefit of the separation, XOOPS 2.6.0 alpha 3 introduces a Service Manager component. ● Services located by service name, not provider ● Service interface established by Contract ● Returns a standardized Response object that includes result, status and messages
  • 7. © 2014 XOOPS Foundation www.xoops.org Service Manager Connection ● Request is based on a well known interface ● Actual provider does not matter to caller ● No need to check for a specific module ● If the service is not available, that status is returned just like any other error condition.
  • 8. © 2014 XOOPS Foundation www.xoops.org if ($xoops->isActiveModule('notifications')) { $notification_handler = Notifications::getInstance()->getHandlerNotification(); $notification_handler->triggerEvent('global', 0, 'category_created', $tags); } Code Simplification $xoops->service('Notify')->triggerEvent('global', 0, 'category_created', $tags); Direct Module Connection Service Manager Connection
  • 9. © 2014 XOOPS Foundation www.xoops.org Service Manager Components namespace XoopsCoreService; AbstractContract.php Abstract Class Contract boilerplate Manager.php Class Manages service providers NullProvider.php Class Provider used when no provider is installed Provider.php Class Basic Provider support Response.php Class Response used by all service providers namespace XoopsCoreServiceContract; This namespace holds interfaces that define all named services. For example, a contract for an 'Avatar' service would be XoopsCoreServiceContractAvatarInterface
  • 10. © 2014 XOOPS Foundation www.xoops.org Service Provider Any module can implement a service provider. To provide a service, the module must respond to a core.service.locate.name event. This is usually accomplished using a PreloadItem. The locate event will supply a Provider object, and the module listener is expected to invoke the register() method of that object with an instance of its own provider implementation.
  • 11. © 2014 XOOPS Foundation www.xoops.org Registering a Service Provider Avatar preload example: /** * listen for core.service.locate.avatar event * * @param Provider $provider - provider object for requested service * * @return void */ public static function eventCoreServiceLocateAvatar(Provider $provider) { if (is_a($provider, 'XoopsCoreServiceProvider')) { $path = dirname(dirname(__FILE__)) . '/class/AvatarsProvider.php'; require $path; $object = new AvatarsProvider(); $provider->register($object); } }
  • 12. © 2014 XOOPS Foundation www.xoops.org Service Provider Implementation Avatar example: use XoopsCoreServiceAbstractContract; use XoopsCoreServiceContractAvatarInterface; class AvatarsProvider extends AbstractContract implements AvatarInterface { // implementation goes here }
  • 13. © 2014 XOOPS Foundation www.xoops.org Service Contract Example namespace XoopsCoreServiceContract; interface AvatarInterface { const MODE = XoopsCoreServiceManager::MODE_EXCLUSIVE; /** * @param Response $response XoopsCoreServiceResponse object * @param mixed $userinfo XoopsUser object * * @return void - response->value absolute URL to avatar image */ public function getAvatarUrl($response, $userinfo); /** * @param Response $response XoopsCoreServiceResponse object * @param mixed $userinfo XoopsUser object * * @return void - response->value absolute URL to edit function */ public function getAvatarEditUrl($response, $userinfo); }
  • 14. © 2014 XOOPS Foundation www.xoops.org Using a Service // get Xoops object $xoops = Xoops::getInstance(); // get provider $provider = $xoops->service('Avatar'); // call contract method $response = $provider->getAvatarUrl($user); // get value from response $avatar = $response->getValue(); // all together $avatar = $xoops->service('Avatar')->getAvatarUrl($user)->getValue();
  • 15. © 2014 XOOPS Foundation www.xoops.org Response Object ● Response objects are managed automatically, so you should never need to instantiate one. ● Useful methods when consuming a service – isSuccess() - true if service call was a success – getValue() - get the value set by the call, can be any PHP type (scalar, array, object, etc.) If no provider is available, getValue() will return NULL. – getErrorMessage – get array of messages ● A Response object is the first argument to all Contract methods, but never included in the service() call – A program calls the service manager – The service manager: • creates a response object • calls the contract method • returns the response object to the caller
  • 16. © 2014 XOOPS Foundation www.xoops.org Contract Methods and Response Objects The service manager handles all response objects and calls the contract providers. To isolate the responsibilities for the response object, it is passed to the contract methods. As a result, the call to the service manager and the call to the contract implementation are different: Service call: $response = $xoops->service("Avatar")->getAvatarUrl($userinfo); Contract definition: public function getAvatarUrl($response, $userinfo);
  • 17. © 2014 XOOPS Foundation www.xoops.org Lazy Service Location Service providers are only instantiated when explicitly requested, and then kept for the duration of the PHP run. A locate event is not triggered until a named service is first requested, so if a service is not used, it has no overhead cost. If no providers for a service are installed, the locate trigger has little cost, and any subsequent calls go straight to a NullProvider that minimizes resource use.
  • 18. © 2014 XOOPS Foundation www.xoops.org Service Manager Administration – For simple cases, just install the provider module / extension and it will just work. – For more complex cases use the services section in the administration area
  • 19. © 2014 XOOPS Foundation www.xoops.org Future of Service Manager ● User side interface to choose a specific provider for MODE_PREFERENCE, for example: – Editors ● Implement MODE_MULTIPLE support, calling multiple providers in sequence. Some possible uses are: – Security inspections – Spam prevention lookups ● Complete conversions and separate additional services – Presently only Avatar provider is implemented – Comments and Notifications to follow – Other possibilities ● Mailer ● Editors ● Captcha ● Image library ● Important part of “everything is a module” strategy
  • 20. 20 © 2014 XOOPS Foundation www.xoops.org If you have any suggestions, comments or questions, please make them known. You can contact the author here : richard@geekwright.com IDEAS ? QUESTIONS ? www.xoops.org