Class CloudEdgeSwitch

java.lang.Object
org.chenile.core.interceptors.BaseChenileInterceptor
org.chenile.cloudedgeswitch.interceptor.CloudEdgeSwitch
All Implemented Interfaces:
Command<ChenileExchange>

public class CloudEdgeSwitch extends BaseChenileInterceptor

This interceptor, if configured, acts like an edge switch for a service i.e. it turns a service from a cloud service into an edge service.

This switch looks for a property called remoteUrl. If the remote Url is not configured then it assumes that the service is running in the cloud. For the cloud it merely passes control to the service and publishes a message upon successful execution so that all edges can update themselves

If the remoteUrl is configured then it switches the functionality to the "edge" mode.

The edge service logic is as follows:
* If the cloud service is detected and can be successfully invoked synchronously via HTTP, then the edge service is a "forward only" service. Else it is a "store and forward service"

The local service call is bypassed completely at the edge. The Switch attempts to call the same service but hosted in the cloud. The remote url is the cloud location of the service. If the cloud call is successful, then this effectively acts as if the edge service is a traffic cop merely directing all the incoming traffic to the cloud and returning the result of the cloud service call. This is the 'forward only' functionality

If the call fails due to a problem with the connection (we check this explicitly) then the "store and forward" part of the logic kicks in. In this case the local service is called. If successful, the result of the local service call is returned with a warning stating that the transaction succeeded but it is done locally due to network failure.

Then a message is forwarded to the cloud via MQ-TT. This message, when received, will cause the cloud service to update itself and also notify all the edges (except the edge that notified the cloud in the first place)