/*
* Copyright 2008 GigaSpaces Technologies LTD. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. GIGASPACES WILL NOT
* BE LIABLE FOR ANY DAMAGE OR LOSS IN CONNECTION WITH THE SOFTWARE.
*/
package com.gigaspaces.examples.tutorials.queries.codebasedvalidator;
import org.openspaces.core.GigaSpace;
import org.openspaces.core.GigaSpaceConfigurer;
import org.openspaces.core.space.UrlSpaceConfigurer;
import org.openspaces.events.notify.SimpleNotifyContainerConfigurer;
import org.openspaces.events.notify.SimpleNotifyEventListenerContainer;
import org.openspaces.events.polling.SimplePollingContainerConfigurer;
import org.openspaces.events.polling.SimplePollingEventListenerContainer;
import com.j_spaces.core.IJSpace;
import com.j_spaces.core.client.SQLQuery;
import com.gigaspaces.examples.tutorials.queries.common.OrderEvent;
import com.gigaspaces.examples.tutorials.queries.validator.NormalOrderEventValidator;
import com.gigaspaces.examples.tutorials.queries.validator.InsecureRiskyOrderEventCounter;
/**
* CodeBasedValidator
* <p>
* The validator connects to the remote space and:
* 1. Registers a notify container that receives by notification "Insecure"&"New"
* orders using query, examines and counts according to their risk.
* 2. Starts a polling container that takes "Normal"&"New" orders using query,
* validates them and writes them back to the space as approved/rejected.
*
* This "CodeBased" version of the validator is configured inside the main() method.
* The Processing Unit version of the validator uses a pu.xml configuration file and can
* ran inside a stand alone container or onto GigaSpaces ServiceGrid.
*/
public class CodeBasedValidator {
public static IJSpace space;
public static GigaSpace gigaSpace;
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
space = new UrlSpaceConfigurer("jini:).space();
gigaSpace = new GigaSpaceConfigurer(space).gigaSpace();
SQLQuery<OrderEvent> queryInsecureOrders = new SQLQuery<OrderEvent>(new OrderEvent(),"type='"+OrderEvent.TYPE_INSECURE+"' and status='"+OrderEvent.STATUS_NEW+"'");
SimpleNotifyEventListenerContainer notifyEventListenerContainer =
new SimpleNotifyContainerConfigurer(gigaSpace) /* The space the notify container is connected to */
.template(queryInsecureOrders) /* The query to match */
.eventListenerAnnotation(new InsecureRiskyOrderEventCounter()) /* The listener class containing the method to invoke upon notification (annotated @SpaceDataEvent) */
.notifyContainer();
SQLQuery<OrderEvent> queryNormalOrders = new SQLQuery<OrderEvent>(new OrderEvent(),"type='"+OrderEvent.TYPE_NORMAL+"' and status='"+OrderEvent.STATUS_NEW+"'");
SimplePollingEventListenerContainer pollingEventListenerContainer =
new SimplePollingContainerConfigurer(gigaSpace) /* The space the polling container is connected to */
.template(queryNormalOrders) /* The query to match */
.eventListenerAnnotation(new NormalOrderEventValidator()) /* The class containing the method to invoke upon match (annotated @SpaceDataEvent) */
.pollingContainer();
}
}