如何在Apache Geode中存储多列数据?

时间:2015-08-13 17:25:01

标签: java geode

我是Apache Geode的新手,我正在尝试一个示例程序来存储日期,如:

EMPID:COL1:COL2
1点10分15秒

我编写了一个示例程序,但在运行时它给出的错误如下:"错误在池上注册实例化器:"。如果我浏览日志,我可以看到记录已插入区域,但在查询时我也会收到以下错误:

Result     : false
startCount : 0
endCount   : 20
Message    : A ClassNotFoundException was thrown while trying to deserialize cached value.

分享完整的代码。 DataEntry.java

package com.apache.geode;

import java.util.Map.Entry;

import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
import com.gemstone.gemfire.cache.query.FunctionDomainException;
import com.gemstone.gemfire.cache.query.NameResolutionException;
import com.gemstone.gemfire.cache.query.QueryInvocationTargetException;
import com.gemstone.gemfire.cache.query.TypeMismatchException;

public class DataEntry {

public static void main(String[] args) throws FunctionDomainException,TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    ClientCache cache = new ClientCacheFactory().addPoolLocator(
            "10.77.17.17", 10334).create();
    Region<String, CustomerValue> customer = cache
            .<String, CustomerValue> createClientRegionFactory(
                    ClientRegionShortcut.CACHING_PROXY)
            .setValueConstraint(CustomerValue.class)
            .setKeyConstraint(String.class).create("custRegion");
    CustomerValue customerValue = new CustomerValue(10, 15);
    customer.put("1", customerValue);
    System.out.println("successfully Put customer object into the cache");
    for (Entry<String, CustomerValue> entry : customer.entrySet()) {
        System.out.format("key = %s, value = %s\n", entry.getKey(),
                entry.getValue());
    }
    cache.close();
}

}

ConsumerValue.java

package com.apache.geode;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.Instantiator;

 public class CustomerValue implements DataSerializable{

private static final long serialVersionUID = -5524295054253565345L;
private  int points_5A;
private  int points_10A;

  static {
        Instantiator.register(new Instantiator(CustomerValue.class, 45) {
            public DataSerializable newInstance() {
              return new CustomerValue();
            }
          });
      }
public CustomerValue()
{

}
public CustomerValue(int points_5A,int points_10A)
{
    this.points_10A=points_10A;
    this.points_5A=points_5A;
}
public int getPoints_5A() {
    return points_5A;
}
public void setPoints_5A(int points_5a) {
    points_5A = points_5a;
}
public int getPoints_10A() {
    return points_10A;
}
public void setPoints_10A(int points_10a) {
    points_10A = points_10a;
}

@Override
public String toString()
{
        return "customer [ 5Apoints=" + points_5A +",10Apoints=" + points_10A +"]";
}

public void fromData(DataInput in) throws IOException {
    this.points_5A=in.readInt();
    this.points_10A=in.readInt();

}
public void toData(DataOutput io) throws IOException {
    io.writeInt(points_5A);
    io.writeInt(points_10A);    
}

}

输出日志:

[info 2015/08/13 14:28:23.452 UTC  <main> tid=0x1] Running in local mode since mcast-port was 0 and locators was empty.

[info 2015/08/13 14:28:23.635 UTC  <Thread-0 StatSampler> tid=0x9] Disabling statistic archival.

[config 2015/08/13 14:28:23.881 UTC  <main> tid=0x1] Pool DEFAULT started with multiuser-authentication=false

[config 2015/08/13 14:28:23.938 UTC  <poolTimer-DEFAULT-3> tid=0x13] Updating membership port.  Port changed from 0 to 59,982.

[warning 2015/08/13 14:28:24.176 UTC  <main> tid=0x1] Error registering instantiator on pool:
com.gemstone.gemfire.cache.client.ServerOperationException: : While performing a remote registerInstantiators
    at com.gemstone.gemfire.cache.client.internal.AbstractOp.processAck(AbstractOp.java:257)
    at com.gemstone.gemfire.cache.client.internal.RegisterInstantiatorsOp$RegisterInstantiatorsOpImpl.processResponse(RegisterInstantiatorsOp.java:140)
    at com.gemstone.gemfire.cache.client.internal.AbstractOp.processResponse(AbstractOp.java:219)
    at  com.gemstone.gemfire.cache.client.internal.AbstractOp.attemptReadResponse(AbstractOp.java:167)
    at com.gemstone.gemfire.cache.client.internal.AbstractOp.attempt(AbstractOp.java:373)
    at com.gemstone.gemfire.cache.client.internal.ConnectionImpl.execute(ConnectionImpl.java:261)
    at com.gemstone.gemfire.cache.client.internal.pooling.PooledConnection.execute(PooledConnection.java:323)
    at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.executeWithPossibleReAuthentication(OpExecutorImpl.java:932)
    at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.execute(OpExecutorImpl.java:162)
    at com.gemstone.gemfire.cache.client.internal.PoolImpl.execute(PoolImpl.java:660)
    at com.gemstone.gemfire.cache.client.internal.RegisterInstantiatorsOp.execute(RegisterInstantiatorsOp.java:42)
    at com.gemstone.gemfire.internal.cache.PoolManagerImpl.allPoolsRegisterInstantiator(PoolManagerImpl.java:219)
    at com.gemstone.gemfire.internal.InternalInstantiator.sendRegistrationMessageToServers(InternalInstantiator.java:206)
    at com.gemstone.gemfire.internal.InternalInstantiator._register(InternalInstantiator.java:161)
    at com.gemstone.gemfire.internal.InternalInstantiator.register(InternalInstantiator.java:89)
    at com.gemstone.gemfire.Instantiator.register(Instantiator.java:175)
    at CustomerValue.<clinit>(CustomerValue.java:16)
    at DataEntry.main(DataEntry.java:22)
Caused by: java.lang.ClassNotFoundException: CustomerValue$1
    at com.gemstone.gemfire.internal.ClassPathLoader.forName (ClassPathLoader.java:422)
    at com.gemstone.gemfire.internal.InternalDataSerializer.getCachedClass (InternalDataSerializer.java:4066)
    at  com.gemstone.gemfire.internal.cache.tier.sockets.command.RegisterInstantiators.cmdExecute(RegisterInstantiators.java:89)
    at com.gemstone.gemfire.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:182)
    at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.doNormalMsg(ServerConnection.java:787)
    at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.doOneMessage(ServerConnection.java:914)
    at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1159)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at com.gemstone.gemfire.internal.cache.tier.sockets.AcceptorImpl$1$1.run(AcceptorImpl.java:580)
    at java.lang.Thread.run(Thread.java:745)
successfully Put customer object into the cache
key = 1, value = customer [ 5Apoints=10,10Apoints=15]

[info 2015/08/13 14:28:24.225 UTC  <main> tid=0x1] GemFireCache[id = 712610161; isClosing = true; isShutDownAll = false; closingGatewayHubsByShutdownAll = false; created = Thu Aug 13 14:28:23 UTC 2015; server = false; copyOnRead = false; lockLease = 120; lockTimeout = 60]: Now closing.

[info 2015/08/13 14:28:24.277 UTC  <main> tid=0x1] Resetting original MemoryPoolMXBean heap threshold bytes 0 on pool PS Old Gen

[config 2015/08/13 14:28:24.329 UTC  <main> tid=0x1] Destroying connection pool DEFAULT

1 个答案:

答案 0 :(得分:1)

您的CustomerValue类需要位于服务器的类路径上。有关如何将jar部署到服务器,请参阅geode documentation