|
|
|
Re: writing a cloudlet [message #1713284 is a reply to message #1713281] |
Tue, 03 November 2015 05:45 |
|
I have an example that might help you in understanding the Cloudlet scenario and its usage.
@Component(immediate = true, name = "com.amitinside.activity.log.service")
@Service(value = { IActivityLogService.class })
public class ActivityLogService extends Cloudlet implements IActivityLogService {
/**
* Defines Application ID for Activity Logs
*/
private static final String APP_ID = "LOGS-V1";
/**
* Logger.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(ActivityLogService.class);
/**
* Cloud Service Injection
*/
@Reference(bind = "bindCloudService", unbind = "unbindCloudService")
private volatile CloudService m_cloudService;
/**
* Constructor
*/
public ActivityLogService() {
super(APP_ID);
}
/**
* Callback while this component is getting registered
*
* @param properties
* the service configuration properties
*/
@Override
@Activate
protected synchronized void activate(final ComponentContext context) {
LOGGER.info("Activating Activity Log Service....");
super.setCloudService(this.m_cloudService);
super.activate(context);
LOGGER.info("Activating Activity Log Service... Done.");
}
/**
* Kura Cloud Service Binding Callback
*/
public synchronized void bindCloudService(final CloudService cloudService) {
if (this.m_cloudService == null) {
super.setCloudService(this.m_cloudService = cloudService);
}
}
/**
* Callback while this component is getting deregistered
*
* @param properties
* the service configuration properties
*/
@Override
@Deactivate
protected synchronized void deactivate(final ComponentContext context) {
LOGGER.info("Deactivating Activity Log Service....");
super.deactivate(context);
LOGGER.info("Deactivating Activity Log Service... Done.");
}
/** {@inheritDoc} */
@Override
protected void doGet(final CloudletTopic reqTopic, final KuraRequestPayload reqPayload,
final KuraResponsePayload respPayload) throws KuraException {
//if mqtt clients need to retrieve logs
if ("logs".equals(reqTopic.getResources()[0])) {
respPayload.addMetric("tumlog", this.retrieveLogs(LogFileType.TUM));
respPayload.addMetric("kuralog", this.retrieveLogs(LogFileType.KURA));
}
respPayload.setResponseCode(KuraResponsePayload.RESPONSE_CODE_OK);
}
/**
* {@inheritDoc}
*/
@Override
public String retrieveLogs(final LogFileType type) {
LOGGER.debug("Retrieving logs from the Activity Logs Database...");
//Logs retrieval custom implementation
LOGGER.debug("Retrieving logs from the Activity Logs Database...Done");
return "";
}
/**
* {@inheritDoc}
*/
@Override
public void saveLog(final String log) {
LOGGER.debug("Saving log to the Activity Logs Database...");
//Logs storing custom implementation
LOGGER.debug("Saving log to the Activity Logs Database...Done");
}
/**
* Kura Cloud Service Callback while deregistering
*/
public synchronized void unbindCloudService(final CloudService cloudService) {
if (this.m_cloudService == cloudService) {
super.setCloudService(this.m_cloudService = null);
}
}
}
If you have any question, feel free to ask.
Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
|
|
|
|
Powered by
FUDForum. Page generated in 0.02780 seconds