Showing posts with label SCA. Show all posts
Showing posts with label SCA. Show all posts

Saturday, October 1, 2011

SCA (Service Component Architecture)- Part 3

This is the part 3 in the series of articles that will cover SCA(Service Component Architecture). Refer Part 1 and Part 2 before you read this.


How do I use SCA?
Even though SCA composites rely on a domain to handle the intra-component communication, the components by themselves can expose Web Services and allow consumers to interact with them using those Web Services.


Accessing services from SCA component
SCA components can use other SCA components within the same domain by using references.


Accessing services from non-SCA component implementations
Non-SCA components, which are part of the SCA module, get access to services using Module Context. They use ModuleContext in their implementations to find services. The non-SCA component implementation would include a line like the following to get access to the module context:

ModuleContext moduleContext = CurrentModuleContext.getContext().


Accessing services from non-SCA Client
A client can also use the OASIS SCAClient API to invoke a service in a remote SCA domain.The client could be a plain Java SE class with a main method which uses the OASIS SCAClient API to invoke a service in a remote SCA domain.


For instance, we can use the below client assuming, we have a helloworld service running in a SCA domain somewhere. The client needs access to the HelloWorld Interface.


Helloworld OASIS Client


package abc;
import org.oasisopen.sca.NoSuchDomainException;
import org.oasisopen.sca.NoSuchServiceException;
import org.oasisopen.sca.client.SCAClientFactory;


public class HelloworldSCAClient {


    public static void main(String[] args) throws NoSuchDomainException, NoSuchServiceException {


        String domainURI = "uri:default" //or could be uri:default?wka=127.0.0.1:7654
        if (domainURI == null || domainURI.length() < 1) {
            domainURI = ;
        }


        System.out.println("HelloworldSCAClient, using domainURI " + domainURI);
        SCAClientFactory factory = SCAClientFactory.newInstance(URI.create(domainURI));


        String name = args.length < 1 ? "world" : args[0];
        System.out.println("Calling HelloworldComponent.sayHello(\"" + name + "\"):");
        Helloworld service = factory.getService(Helloworld.class, "HelloworldComponent");
        System.out.println(service.sayHello(name));
     }

}




SCA Policy Framework


SCA defines a policy framework that has:


  • Interaction Policies
Policies that might apply to bindings, for instance Security etc.
  • Implementation Policies
Local policies that apply to how a component behaves within the SCA domain. For instance the requirement that there be a transaction for this component. The intersection set between two components policies determine how they communicate with each other. Typically one domain has one security policy( double check)

These policies can be defined using WS-Policy for communication outside the domain. Communication inside the domain are not defined by the spec, so the SCA runtime is free to choose the mechanism.


Example:
PolicySet defines the list of policies and the service/reference/binding indicates which policies to apply.



<service name="MyService“ promote=“SomeComponent” requires="sca:myAuthPolicy">
   <interface.java interface="someInterface"/>
   <binding.ws port="http://host/Myservice"/>
</service>
<reference name="MyServiceRef“ promote=“SomeComponent/someService”>
   <interface.java interface="someInterface2"/>
   <binding.ws port="http://host/Myservice2" requires=“sca:myAuthPolicy”/>
</reference>




<policySet name="sca:MyUserNameToken" provides="sca:myAuthPolicy" appliesTo="sca:binding.ws">
   <wsp:Policy>
        <sp:SupportingToken>
            <wsp:Policy>
             <sp:UserNameToken>
              </sp:UserNameToken>
             </wsp:Policy>
       </sp:SupportingToken>
    </wsp:Policy>
</policySet>

The opinions and statements in this communication are my own and do not necessarily reflect the opinions or policies of CA.

Thursday, September 1, 2011

SCA(Service Component Architecture)- Part 1

This is the part 1 in the series of articles that will cover the first three sections in the following aspects of SCA(Service Component Architecture):

  • What is SCA?
  • Is SCA better than JBI?
  • When do I use SCA?
  • How do I create an SCA Component/Composite?
  • How do I consume SCA?

What is SCA?
SCA can be plainly thought of as a way to create components and then assemble them so that they can work together. The Components that make up an application, can be built in Java or any one of the programming languages supported by SCA. A different technology, for instance, BPEL can be used as well.


Component   
The components vary in complexity, ranging from a simple java classes to ones which have multiple components including local or distributed Java classes, BPEL components etc. SCA defined a logical construct called composites which is nothing but an assembly of components. An application could consist of one composite or multiple. The components could be implemented using different languages or technologies if so desired. However, the components themselves have a few fundamental features:


  • Business logic exposed as Services. A Service is nothing but a set of operations that be invoked by a client.For instance a Java component might use an interface to describe the service.
  • Consuming other services as References
  • Property allows a component to read configuration or other initialization data.
  • binding can be thought of as a protocol to communicate with the service or reference and there can be multiple bindings per service/reference.


                                                           Figure 1: A component
SDO
SCA components can access data using SDO along with JDBC or JPA from a database. SDO is optional and can be thought of as the "DAO" pattern that Java defines. SDO might be the subject of another post later on.


Composite


An SCA composite is an ".composite" file which uses an XML-based format called the Service Component Definition Language (SCDL) to describe the components and their relationship.Example:




<composite name="myComposite">
   <component name="abc">
    ...
   </component>
   <component name="xyz">
      ...
   </component>
</composite>


                                                 Figure 2: A Composite




Domains
It's tough to describe domains in a way that most of us understand the word domain. Domains can be thought of as multiple SCA runtimes installed in local or distributed fashion. Since SCA doesn't define how distributed domains communicate with each other, its tough to describe what truly makes up a domain and how to map the definition of a composite to different domains? I may have not understood the specs correctly but t's probably not possible in SCA to have a composite cross multiple domains.  To me this is a significant limitation that I am hoping somebody clarifies.


(Maybe OSGI remote services can help here but that is the subject of a future post).




                                                Figure 3: An SCA Domain


Is SCA better than JBI?
It's like comparing apples to oranges ( Sorry, it's always fun to say this :-) ). To put it very succinctly JBI is what middleware vendors can use to provide or extend the runtime. SCA is what developers and assemblers can use to develop and deploy services ( as components and composites). So there is some overlap but not much. To me they are complementary and probably debated a lot because of Sun versus the "others" focus. Sun was focusing ( not sure if they still do) on JBI and the "others" were focusing on SCA. Probably what Sun is proposing has more to do with the middleware vendors themselves which the "others" are trying to avoid by focusing on the programming and component model instead of how the runtime is expected to behave.

   JBI would be more applicable for ESB vendors than component developers but I still think JBI has a role to play in Enterprise architectures because we do need more than a "point-to-point" model which SCA proposes. What if I have an SCA component that needs to broadcast a message(or event) which needs to be transformed differently for each of the target endpoints? It would be interesting to find out, how would this be implemented in SCA? Maybe we will have some "component" that either intercepts the point to point communication( is there such a thing in SCA?) or the message is actually directed to this mediator  (this breaks loose coupling?) which can then use BPEL, JMS or some other fan-out mechanism to broadcast this to the other components? Do I see an SCA+ Camel combination coming? :-)

I would hope that there is more synergy between JBI and SCA and this article does talk about one. It's from 2008, so I am not sure if this was updated or improved in recent time.

When do I use SCA?
SCA should be used to implement SOA when the organization doesn't already have any well-established SOA culture. Most often, the organization either has or tries to create a bunch of web services hoping that it would lead to SOA. Having web services is a good thing but it cannot lead to SOA unless the following criteria are met:

  • Loosely coupled. A web service that depends on another web service to finish it's processing is not SOA. It cannot reliably predict if the other service is running or even SHOULD be running. Web services should be truly independant of each other and no assumptions should be made as to their availability.
  • Composition of web services. Some framework or mechanism to exist that can combine, orchestrate or choreograph ( I won't go into the difference here :-) ) these services to implement business logic. Without effective coordination, having web services that are controlled by some inflexible and non-declarative piece of software is as bad as not having the web services in the first place.
  • Location Transparency: Again, services should be registered and located in a way that avoids violating the loosely coupled principle. It also means that there is a single mechanism to find and locate services and it's well established.
  • QoS, Governance: Without effective QoS and Governance support, web services are hard to maintain and grow. Do we know what is the impact of bringing down a particular service? Who can access a particular service? What are the Web service policy requirements and wow can a client satisfy these requirements?

SCA is a step forward in that direction as it has a bunch of specifications that can define how to create Service Oriented Business Applications ( SOBA). These specifications achieve the above SOA requirements and should be .  SCA has a programming model that allows one to use any of the supported programming languages ( C++, Java, BPEL etc).


Additionally, SCA provides the following things:
  • A platform neutral service component model that spans technologies and is not dependent on a particular language.
  • A client programming model to allow clients to access service components deployed in the runtime. SCA Developers can develop components using the various technologies they are familiar with, such as Enterprise Java Bean (EJBs), and use SCA to glue the components together.
  • Defines a standard model for defining dependencies between components. These dependencies are defined by wiring SCA components together using references.
  • Defines a standard deployment model for packaging components into a service module.
  • SCA has multiple bindings ( and not just web services) including JMS, BPEL, REST etc. I read about an interesting aspect of this when someone used SCA to define a "widget" composite/component in SCA and then provided the implementation of that Widget in HTML/JS. The Widget component was using the java components as references within the HTML/JS code. JSON and ATOM binding was used to expose the java components over the wire. A very interesting example of SCA indeed! I would have to locate this resource and link it here. If any one of you can find it, please let me know. 
  • An asynchronous programming model.


Caution:
An SCA runtime can implemented many different bindings including Web service, JMS, JCA, EJB etc. There is also an SCA service binding which is not defined by the spec and can be used only within a domain by an SCA runtime.The implementation of this binding type is not intended to be inter-operable. For interoperability the standardized binding types like web services should be used.

The opinions and statements in this communication are my own and do not necessarily reflect the opinions or policies of CA.