1 5 package com.tc.l2.handler; 6 7 import com.tc.async.api.AbstractEventHandler; 8 import com.tc.async.api.ConfigurationContext; 9 import com.tc.async.api.EventContext; 10 import com.tc.async.api.Sink; 11 import com.tc.io.TCByteBufferOutputStream; 12 import com.tc.l2.context.ManagedObjectSyncContext; 13 import com.tc.object.dna.impl.ObjectStringSerializer; 14 import com.tc.objectserver.api.ObjectManager; 15 import com.tc.objectserver.core.api.ManagedObject; 16 import com.tc.objectserver.core.api.ServerConfigurationContext; 17 18 import java.util.Iterator ; 19 import java.util.Map ; 20 21 public class L2ObjectSyncDehydrateHandler extends AbstractEventHandler { 22 23 private Sink sendSink; 24 private ObjectManager objectManager; 25 26 public void handleEvent(EventContext context) { 27 ManagedObjectSyncContext mosc = (ManagedObjectSyncContext) context; 28 Map moObjects = mosc.getObjects(); 29 ObjectStringSerializer serializer = new ObjectStringSerializer(); 31 TCByteBufferOutputStream out = new TCByteBufferOutputStream(); 32 for (Iterator i = moObjects.values().iterator(); i.hasNext();) { 33 ManagedObject m = (ManagedObject) i.next(); 34 m.toDNA(out, serializer); 35 objectManager.releaseReadOnly(m); 36 } 37 mosc.setDehydratedBytes(out.toArray(), moObjects.size(), serializer); 38 sendSink.add(mosc); 39 } 40 41 public void initialize(ConfigurationContext context) { 42 super.initialize(context); 43 ServerConfigurationContext oscc = (ServerConfigurationContext) context; 44 this.objectManager = oscc.getObjectManager(); 45 this.sendSink = oscc.getStage(ServerConfigurationContext.OBJECTS_SYNC_SEND_STAGE).getSink(); 46 } 47 } 48 | Popular Tags |