Skip to content

Commit

Permalink
Optimize marshalled size of cache keys used for distributed EJBs.
Browse files Browse the repository at this point in the history
Optimize marshalled size of client mappings.
  • Loading branch information
pferraro committed Sep 9, 2015
1 parent 94b35af commit 55cecb3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Expand Up @@ -23,13 +23,14 @@
package org.wildfly.clustering.ejb.infinispan; package org.wildfly.clustering.ejb.infinispan;


import org.jboss.ejb.client.BasicSessionID; import org.jboss.ejb.client.BasicSessionID;
import org.wildfly.clustering.marshalling.jboss.IndexExternalizer;


/** /**
* @author Paul Ferraro * @author Paul Ferraro
*/ */
public class BasicSessionIDExternalizer extends SessionIDExternalizer { public class BasicSessionIDExternalizer extends SessionIDExternalizer {


public BasicSessionIDExternalizer() { public BasicSessionIDExternalizer() {
super(BasicSessionID.class); super(BasicSessionID.class, IndexExternalizer.UNSIGNED_BYTE);
} }
} }
Expand Up @@ -28,6 +28,7 @@


import org.jboss.as.network.ClientMapping; import org.jboss.as.network.ClientMapping;
import org.wildfly.clustering.marshalling.Externalizer; import org.wildfly.clustering.marshalling.Externalizer;
import org.wildfly.clustering.marshalling.jboss.IndexExternalizer;


/** /**
* @author Paul Ferraro * @author Paul Ferraro
Expand All @@ -37,21 +38,21 @@ public class ClientMappingExternalizer implements Externalizer<ClientMapping> {
@Override @Override
public void writeObject(ObjectOutput output, ClientMapping mapping) throws IOException { public void writeObject(ObjectOutput output, ClientMapping mapping) throws IOException {
byte[] address = mapping.getSourceNetworkAddress().getAddress(); byte[] address = mapping.getSourceNetworkAddress().getAddress();
output.writeInt(address.length); IndexExternalizer.UNSIGNED_BYTE.writeData(output, address.length);
output.write(address); output.write(address);
output.writeInt(mapping.getSourceNetworkMaskBits()); IndexExternalizer.UNSIGNED_BYTE.writeData(output, mapping.getSourceNetworkMaskBits());
output.writeUTF(mapping.getDestinationAddress()); output.writeUTF(mapping.getDestinationAddress());
output.writeInt(mapping.getDestinationPort()); IndexExternalizer.UNSIGNED_SHORT.writeData(output, mapping.getDestinationPort());
} }


@Override @Override
public ClientMapping readObject(ObjectInput input) throws IOException { public ClientMapping readObject(ObjectInput input) throws IOException {
byte[] sourceAddress = new byte[input.readInt()]; byte[] sourceAddress = new byte[IndexExternalizer.UNSIGNED_BYTE.readData(input)];
input.readFully(sourceAddress); input.readFully(sourceAddress);
int sourcePort = input.readInt(); int sourceNetworkMaskBits = IndexExternalizer.UNSIGNED_BYTE.readData(input);
String destAddress = input.readUTF(); String destAddress = input.readUTF();
int destPort = input.readInt(); int destPort = IndexExternalizer.UNSIGNED_SHORT.readData(input);
return new ClientMapping(InetAddress.getByAddress(sourceAddress), sourcePort, destAddress, destPort); return new ClientMapping(InetAddress.getByAddress(sourceAddress), sourceNetworkMaskBits, destAddress, destPort);
} }


@Override @Override
Expand Down
Expand Up @@ -34,21 +34,23 @@
public class SessionIDExternalizer implements Externalizer<SessionID> { public class SessionIDExternalizer implements Externalizer<SessionID> {


private final Class<? extends SessionID> targetClass; private final Class<? extends SessionID> targetClass;
private final Externalizer<Integer> externalizer;


SessionIDExternalizer(Class<? extends SessionID> targetClass) { SessionIDExternalizer(Class<? extends SessionID> targetClass, Externalizer<Integer> externalizer) {
this.targetClass = targetClass; this.targetClass = targetClass;
this.externalizer = externalizer;
} }


@Override @Override
public void writeObject(ObjectOutput output, SessionID id) throws IOException { public void writeObject(ObjectOutput output, SessionID id) throws IOException {
byte[] encoded = id.getEncodedForm(); byte[] encoded = id.getEncodedForm();
output.writeInt(encoded.length); this.externalizer.writeObject(output, encoded.length);
output.write(encoded); output.write(encoded);
} }


@Override @Override
public SessionID readObject(ObjectInput input) throws IOException { public SessionID readObject(ObjectInput input) throws IOException, ClassNotFoundException {
byte[] encoded = new byte[input.readInt()]; byte[] encoded = new byte[this.externalizer.readObject(input)];
input.readFully(encoded); input.readFully(encoded);
return SessionID.createSessionID(encoded); return SessionID.createSessionID(encoded);
} }
Expand Down
Expand Up @@ -23,13 +23,14 @@
package org.wildfly.clustering.ejb.infinispan; package org.wildfly.clustering.ejb.infinispan;


import org.jboss.ejb.client.UnknownSessionID; import org.jboss.ejb.client.UnknownSessionID;
import org.wildfly.clustering.marshalling.jboss.IndexExternalizer;


/** /**
* @author Paul Ferraro * @author Paul Ferraro
*/ */
public class UnknownSessionIDExternalizer extends SessionIDExternalizer { public class UnknownSessionIDExternalizer extends SessionIDExternalizer {


public UnknownSessionIDExternalizer() { public UnknownSessionIDExternalizer() {
super(UnknownSessionID.class); super(UnknownSessionID.class, IndexExternalizer.VARIABLE);
} }
} }

0 comments on commit 55cecb3

Please sign in to comment.