All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wildfly.clustering.marshalling.jboss.IdentityObjectTable Maven / Gradle / Ivy

The newest version!
/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.marshalling.jboss;

import java.io.IOException;
import java.util.List;

import org.jboss.marshalling.Marshaller;
import org.jboss.marshalling.ObjectTable;
import org.jboss.marshalling.Unmarshaller;
import org.wildfly.common.function.ExceptionBiConsumer;

/**
 * An {@link ObjectTable} based on an {@link IdentityTable}.
 * @author Paul Ferraro
 */
public class IdentityObjectTable implements ObjectTable {

	private final IdentityTable table;

	public IdentityObjectTable(List objects) {
		this.table = IdentityTable.from(objects);
	}

	@Override
	public Writer getObjectWriter(Object object) throws IOException {
		ExceptionBiConsumer writer = this.table.findWriter(object);
		return writer != null ? writer::accept : null;
	}

	@Override
	public Object readObject(Unmarshaller unmarshaller) throws IOException, ClassNotFoundException {
		return this.table.read(unmarshaller);
	}
}