2015-08-13 42 views
2

我是新來的Apache的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

你CustomerValue類需求放在服務器的類路徑上。有關如何將jar部署到服務器,請參閱geode documentation

+0

哇它工作:-)非常感謝。我仍然在想我是如何錯過這種方式的;-) – OneUser

相關問題