Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

SpaceDataEvent does not execute on client

His,

i am stuck with this problem of trying to have my data event handler on the client application execute on stock update event, which happens on the server (all done on the same machine).

The strange thing is that I have tried out 2 versions - the first all done in code (no xml configuration files, the second with xml configuration files) - and only the pure-code version works.

I am using gigaspaces-xapcommunity-6.5.0-ga. I would appreciate if anyone could suggest at how I else should try debug it or hint at a likely mistake?

Here are the code excerpts:


StockClientCode.java (1 file, executes and runs fine, updated stocks are displayed in the console)

package mypackage;

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.example.stock.common.Stock;

public class StockClientCode {

public static void main(String args[]) throws InterruptedException {

    UrlSpaceConfigurer urlSpaceConfigurer = new UrlSpaceConfigurer(
            "jini://*/*/stockSpace");
    GigaSpace space = new GigaSpaceConfigurer(urlSpaceConfigurer.space())
            .defaultTakeTimeout(1000).defaultReadTimeout(1000).gigaSpace();

    new SimpleNotifyContainerConfigurer(space).template(new Stock())
            .eventListenerAnnotation(new StockEventReporter()).fifo(true)
            .notifyWrite(true).notifyUpdate(true).notifyContainer();

    Thread.sleep(10000000);
}

}

==================

DOES NOT EXECUTE, three files, it seems that the event does not get called at all


StockClient.java

package mypackage;

import org.openspaces.example.stock.common.GigaSpaceStockDao; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.UrlResource;

public class StockClient {

public StockClient() {
    System.out.println("StockClient instantiated");
}

public static void main(String args[]) throws InterruptedException {

    XmlBeanFactory factory = new XmlBeanFactory(new UrlResource(
            StockClient.class.getResource("space_and_event.xml")));

    GigaSpaceStockDao dao = (GigaSpaceStockDao) factory.getBean("stockDao");
    System.out.println("Stocks with I: "
            + dao.getStocksByFilter("I").length);

    // ((SimpleNotifyEventListenerContainer)
    // factory.getBean("accountDataNotifyContainer")).start();
    Thread.sleep(10000);
}

}


StockEventReporter.java

package mypackage;

import org.openspaces.events.adapter.SpaceDataEvent;

public class StockEventReporter {

public StockEventReporter() {
    System.out.println("*StockEventReporter INITIALIZED*");
}

@SpaceDataEvent
public void dataProcessed(Object data) {
    System.out.println("***EVENT with Spring:***: " + data);
}

}


space_ant_event.xml

http://www.springframework.org/schema... http://www.openspaces.org/schema/core http://www.openspaces.org/schema/core... http://www.openspaces.org/schema/events http://www.openspaces.org/schema/even... http://www.openspaces.org/schema/remo... http://www.openspaces.org/schema/remo... http://www.openspaces.org/schema/jms http://www.openspaces.org/schema/jms/... http://www.springframework.org/schema... http://www.springframework.org/schema... http://www.openspaces.org/schema/sla http://www.openspaces.org/schema/sla/...>

<bean id="propertiesConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />

<context:annotation-config />

<os-core:space id="space" url="jini://*/*/stockSpace" />
<os-core:giga-space id="remoteGigaSpace" space="space" />

<bean id="stockDao"
    class="org.openspaces.example.stock.common.GigaSpaceStockDao">
    <property name="remoteGigaSpace" ref="remoteGigaSpace" />
</bean>


<bean id="stockEventReporter"
    class="mypackage.StockEventReporter" />


<os-events:notify-container id="simpleId"
    giga-space="remoteGigaSpace">
    <os-events:notify write="true" update="true" />
    <os-core:template>
        <bean class="org.openspaces.example.stock.common.Stock" />
    </os-core:template>
    <!-- os-core:sql-query where="" class="org.openspaces.example.stock.common.Stock"/-->
    <!-- query does not return results either -->
    <os-events:listener>
        <os-events:annotation-adapter>
            <os-events:delegate ref="stockEventReporter" />
        </os-events:annotation-adapter>
    </os-events:listener>
</os-events:notify-container>

</beans>


thanks

Edited by: purposeful.email purposeful.email on Jul 3, 2008 4:32 AM h4. Attachments

[space_ant_event.xml|/upfiles/13759717919338636.xml]

[StockClient.java|/upfiles/13759717913627236.java]

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=2433]{quote}

asked 2008-07-03 04:31:09 -0600

asdfasdf gravatar image

updated 2013-08-08 09:52:00 -0600

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

Can you post your org.openspaces.example.stock.common.Stock?
Shay

Attachments

  1. spaceantevent.xml
  2. StockClient.java

answered 2008-07-03 10:31:04 -0600

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Sure, it is actually from the StockDemo example at [ http://openspaces.org/display/DAE/Ope... ]. I am trying to change the client side of the application.

  • Copyright 2006-2007 the original author or authors. package org.openspaces.example.stock.common;

import com.gigaspaces.annotation.pojo.*;

/** * Represents a stock, which is the system's internal representation of stock related data. * Every {@link org.openspaces.example.stock.common.StockFeedEntry} is consumed by the * {@link org.openspaces.example.stock.processor.StockFeedConverter} which updates the * matching {@link org.openspaces.example.stock.common.Stock} object in the space. */ public class Stock implements Serializable { private String symbol; private String companyName; private String exchange; private Double currentPrice; private Double prevPrice; private Date lastChanged;

public Stock(){}

/**
 * Build a new Stock. 
 *
 * @param symbol       The ticker symbol
 * @param company      The company the stock represents
 * @param exchange     The exchange on which the stock is traded
 * @param currentPrice The last known traded price of the Stock
 */
public Stock(String symbol, String company, String exchange, Double currentPrice)
{
    this.symbol = symbol;
    this.companyName = company;
    this.exchange = exchange;
    this.currentPrice = currentPrice;
    this.prevPrice = currentPrice;
    this.lastChanged = new Date();
}

public void setSymbol(String symbol)
{
    this.symbol = symbol;
}

@SpaceId
@SpaceRouting
public String getSymbol()
{
    return symbol;
}

public void setExchange(String exchange)
{
    this.exchange = exchange;
}

public String getExchange()
{
    return exchange;
}

public void setCurrentPrice(Double currentPrice)
{
    this.prevPrice = this.currentPrice;
    this.currentPrice = currentPrice;
    this.lastChanged = new Date();
}

public Double getCurrentPrice()
{
    return currentPrice;
}

public void setCompanyName(String companyName)
{
    this.companyName = companyName;
}

public String getCompanyName()
{
    return companyName;
}

public Double getPrevPrice()
{
    return prevPrice;
}

public Double getLastChangeValue()
{
    return currentPrice - prevPrice;
}

public Double getLastChangePct()
{
    return (getLastChangeValue() / prevPrice) * 100;
}

public Date getLastChanged()
{
    return lastChanged;
}

public void setPrevPrice(Double prevPrice)
{
    this.prevPrice = prevPrice;
}

public void setLastChanged(Date lastChanged)
{
    this.lastChanged = lastChanged;
}

@Override
public String toString()
{
    return symbol + ";" + companyName + ";" + exchange + ";" + currentPrice + ";" + lastChanged;
}

@Override
public boolean equals(Object o)
{
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Stock that = (Stock) o;

    if (symbol != null ? !symbol.equals(that.symbol) : that.symbol != null) return false;

    return true;
}

@Override
public int hashCode()
{
    return (symbol != null ? symbol.hashCode() : 0);
}

} h4. Attachments

[space_ant_event.xml|/upfiles/13759717912768991.xml]

[StockClient.java|/upfiles/13759717911891491.java]

asdfasdf gravatar imageasdfasdf ( 2008-07-03 16:38:18 -0600 )edit

Hi

You should have used Spring's ClasspathXmlApplicationContext in your StockClient. Also, the configuration for the GigaSpaceStockDao in your xml file was missing (you didn't set the localGigaSpace variable). I attached the corrected versions of these two files to this post.

Uri h4. Attachments

[space_ant_event.xml|/upfiles/13759717923152613.xml]

[StockClient.java|/upfiles/13759717927953413.java]

uri gravatar imageuri ( 2008-07-07 10:45:22 -0600 )edit

His,

I have applied your changes to the files. Everything works just fine.

Many thanks!

asdfasdf gravatar imageasdfasdf ( 2008-07-14 16:25:12 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2008-07-03 04:31:09 -0600

Seen: 55 times

Last updated: Jul 03 '08