repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/CompositeImmutableTimerMetaData.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.io.IOException; import java.lang.reflect.Method; import java.time.Duration; import java.time.Instant; import java.util.function.Predicate; import org.wildfly.clustering.ejb.timer.ImmutableTimerMetaData; import org.wildfly.clustering.ejb.timer.TimerConfiguration; import org.wildfly.clustering.ejb.timer.TimerType; import org.wildfly.clustering.marshalling.spi.Marshaller; /** * @author Paul Ferraro */ public class CompositeImmutableTimerMetaData<V> implements ImmutableTimerMetaData { private final TimerCreationMetaData<V> creationMetaData; private final TimerAccessMetaData accessMetaData; private final Marshaller<Object, V> marshaller; private final boolean persistent; public CompositeImmutableTimerMetaData(TimerMetaDataConfiguration<V> configuration, TimerCreationMetaData<V> creationMetaData, TimerAccessMetaData accessMetaData) { this.marshaller = configuration.getMarshaller(); this.creationMetaData = creationMetaData; this.accessMetaData = accessMetaData; this.persistent = configuration.isPersistent(); } @Override public TimerType getType() { return this.creationMetaData.getType(); } @Override public Object getContext() { try { return this.marshaller.read(this.creationMetaData.getContext()); } catch (IOException e) { throw new IllegalArgumentException(e); } } @Override public boolean isPersistent() { return this.persistent; } @Override public Instant getLastTimout() { Duration lastTimeout = this.accessMetaData.getLastTimout(); return (lastTimeout != null) ? this.creationMetaData.getStart().plus(lastTimeout) : null; } @Override public Instant getNextTimeout() { return this.creationMetaData.apply(this.getLastTimout()); } @Override public <TC extends TimerConfiguration> TC getConfiguration(Class<TC> configurationClass) { return configurationClass.cast(this.creationMetaData); } @Override public Predicate<Method> getTimeoutMatcher() { return this.creationMetaData.getTimeoutMatcher(); } }
3,262
34.086022
168
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/TimerIndexMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.io.IOException; import org.infinispan.protostream.descriptors.WireType; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * @author Paul Ferraro */ public enum TimerIndexMarshaller implements ProtoStreamMarshaller<TimerIndex> { INSTANCE; private static final int NO_PARAMETERS_DECLARING_CLASS_NAME_INDEX = 1; private static final int TIMER_PARAMETERS_DECLARING_CLASS_NAME_INDEX = 2; private static final int METHOD_NAME_INDEX = 3; private static final int INDEX_INDEX = 4; private static final String DEFAULT_METHOD_NAME = "ejbTimeout"; private static final int DEFAULT_INDEX = 0; @Override public Class<? extends TimerIndex> getJavaClass() { return TimerIndex.class; } @Override public TimerIndex readFrom(ProtoStreamReader reader) throws IOException { String declaringClassName = null; String methodName = DEFAULT_METHOD_NAME; int parameters = 0; int index = DEFAULT_INDEX; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case TIMER_PARAMETERS_DECLARING_CLASS_NAME_INDEX: parameters = 1; case NO_PARAMETERS_DECLARING_CLASS_NAME_INDEX: declaringClassName = reader.readString(); break; case METHOD_NAME_INDEX: methodName = reader.readString(); break; default: reader.skipField(tag); } } return new TimerIndex(declaringClassName, methodName, parameters, index); } @Override public void writeTo(ProtoStreamWriter writer, TimerIndex index) throws IOException { writer.writeString(index.getParameters() > 0 ? TIMER_PARAMETERS_DECLARING_CLASS_NAME_INDEX : NO_PARAMETERS_DECLARING_CLASS_NAME_INDEX, index.getDeclaringClassName()); String methodName = index.getMethodName(); if (!methodName.equals(DEFAULT_METHOD_NAME)) { writer.writeString(METHOD_NAME_INDEX, methodName); } if (index.getIndex() != DEFAULT_INDEX) { writer.writeUInt32(INDEX_INDEX, index.getIndex()); } } }
3,513
39.390805
174
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/InfinispanTimerMetaDataFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.time.Duration; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Map; import org.infinispan.Cache; import org.infinispan.context.Flag; import org.wildfly.clustering.ejb.timer.ImmutableTimerMetaData; import org.wildfly.clustering.ejb.timer.TimerMetaData; /** * @author Paul Ferraro */ public class InfinispanTimerMetaDataFactory<I, V> implements TimerMetaDataFactory<I, V> { private final Cache<TimerIndexKey, I> indexCache; private final Cache<TimerCreationMetaDataKey<I>, TimerCreationMetaData<V>> creationMetaDataReadCache; private final Cache<TimerCreationMetaDataKey<I>, TimerCreationMetaData<V>> creationMetaDataWriteCache; private final Cache<TimerAccessMetaDataKey<I>, Duration> accessMetaDataCache; private final TimerMetaDataConfiguration<V> config; public InfinispanTimerMetaDataFactory(TimerMetaDataConfiguration<V> config) { this.config = config; this.indexCache = config.getCache(); this.creationMetaDataReadCache = config.getReadForUpdateCache(); this.creationMetaDataWriteCache = config.getSilentWriteCache(); this.accessMetaDataCache = config.getSilentWriteCache(); } @Override public Map.Entry<TimerCreationMetaData<V>, TimerAccessMetaData> createValue(I id, Map.Entry<TimerCreationMetaData<V>, TimerIndex> entry) { TimerCreationMetaData<V> creationMetaData = entry.getKey(); TimerIndex index = entry.getValue(); // If an timer with the same index already exists, return null; if ((index != null) && (this.indexCache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK).putIfAbsent(new TimerIndexKey(index), id) != null)) return null; this.creationMetaDataWriteCache.put(new TimerCreationMetaDataKey<>(id), creationMetaData); TimerAccessMetaData accessMetaData = new TimerAccessMetaDataEntry<>(this.accessMetaDataCache, new TimerAccessMetaDataKey<>(id)); return new SimpleImmutableEntry<>(creationMetaData, accessMetaData); } @Override public Map.Entry<TimerCreationMetaData<V>, TimerAccessMetaData> findValue(I id) { TimerCreationMetaData<V> creationMetaData = this.creationMetaDataReadCache.get(new TimerCreationMetaDataKey<>(id)); return (creationMetaData != null) ? new SimpleImmutableEntry<>(creationMetaData, new TimerAccessMetaDataEntry<>(this.accessMetaDataCache, new TimerAccessMetaDataKey<>(id))) : null; } @Override public boolean remove(I id) { TimerCreationMetaDataKey<I> key = new TimerCreationMetaDataKey<>(id); TimerCreationMetaData<V> creationMetaData = this.creationMetaDataReadCache.get(key); if (creationMetaData != null) { this.accessMetaDataCache.remove(new TimerAccessMetaDataKey<>(id)); this.creationMetaDataWriteCache.remove(key); return true; } return false; } @Override public TimerMetaData createTimerMetaData(I id, Map.Entry<TimerCreationMetaData<V>, TimerAccessMetaData> entry) { return new CompositeTimerMetaData<>(this.config, entry.getKey(), entry.getValue()); } @Override public ImmutableTimerMetaData createImmutableTimerMetaData(Map.Entry<TimerCreationMetaData<V>, TimerAccessMetaData> entry) { return new CompositeImmutableTimerMetaData<>(this.config, entry.getKey(), entry.getValue()); } }
4,456
46.924731
188
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/ImmutableTimerMetaDataFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.util.Map; import org.wildfly.clustering.ee.Locator; import org.wildfly.clustering.ejb.timer.ImmutableTimerMetaData; /** * @author Paul Ferraro */ public interface ImmutableTimerMetaDataFactory<I, C> extends Locator<I, Map.Entry<TimerCreationMetaData<C>, TimerAccessMetaData>> { ImmutableTimerMetaData createImmutableTimerMetaData(Map.Entry<TimerCreationMetaData<C>, TimerAccessMetaData> entry); }
1,496
39.459459
131
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/InfinispanTimerManagerFactoryConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import org.infinispan.remoting.transport.Address; import org.wildfly.clustering.ee.infinispan.InfinispanConfiguration; import org.wildfly.clustering.ejb.timer.TimerManagerFactoryConfiguration; import org.wildfly.clustering.infinispan.affinity.KeyAffinityServiceFactory; import org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.server.group.Group; /** * @author Paul Ferraro */ public interface InfinispanTimerManagerFactoryConfiguration<I> extends TimerManagerFactoryConfiguration<I>, InfinispanConfiguration { ByteBufferMarshaller getMarshaller(); KeyAffinityServiceFactory getKeyAffinityServiceFactory(); CommandDispatcherFactory getCommandDispatcherFactory(); Group<Address> getGroup(); }
1,905
43.325581
133
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/ImmutableScheduleExpressionMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.io.IOException; import java.time.Instant; import java.time.ZoneId; import java.util.Objects; import org.wildfly.clustering.ejb.timer.ImmutableScheduleExpression; import org.wildfly.clustering.marshalling.protostream.FieldSetMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * @author Paul Ferraro */ public enum ImmutableScheduleExpressionMarshaller implements FieldSetMarshaller<ImmutableScheduleExpression, ImmutableScheduleExpressionBuilder> { INSTANCE; private static final int START_FIELD = 0; private static final int END_FIELD = 1; private static final int YEAR_FIELD = 2; private static final int MONTH_FIELD = 3; private static final int DAY_OF_MONTH_FIELD = 4; private static final int DAY_OF_WEEK_FIELD = 5; private static final int ZONE_FIELD = 6; private static final int HOUR_FIELD = 7; private static final int MINUTE_FIELD = 8; private static final int SECOND_FIELD = 9; private static final int FIELDS = 10; private final ImmutableScheduleExpression defaultExpression = this.getBuilder().build(); @Override public ImmutableScheduleExpressionBuilder getBuilder() { return new ImmutableScheduleExpressionBuilder(); } @Override public int getFields() { return FIELDS; } @Override public ImmutableScheduleExpressionBuilder readField(ProtoStreamReader reader, int index, ImmutableScheduleExpressionBuilder builder) throws IOException { switch (index) { case START_FIELD: return builder.start(reader.readObject(Instant.class)); case END_FIELD: return builder.end(reader.readObject(Instant.class)); case YEAR_FIELD: return builder.year(reader.readString()); case MONTH_FIELD: return builder.month(reader.readString()); case DAY_OF_MONTH_FIELD: return builder.dayOfMonth(reader.readString()); case DAY_OF_WEEK_FIELD: return builder.dayOfWeek(reader.readString()); case ZONE_FIELD: return builder.zone(reader.readObject(ZoneId.class)); case HOUR_FIELD: return builder.hour(reader.readString()); case MINUTE_FIELD: return builder.minute(reader.readString()); case SECOND_FIELD: return builder.second(reader.readString()); default: return builder; } } @Override public void writeFields(ProtoStreamWriter writer, int startIndex, ImmutableScheduleExpression expression) throws IOException { Instant start = expression.getStart(); if (!Objects.equals(start, this.defaultExpression.getStart())) { writer.writeObject(startIndex + START_FIELD, start); } Instant end = expression.getEnd(); if (!Objects.equals(end, this.defaultExpression.getEnd())) { writer.writeObject(startIndex + END_FIELD, end); } String year = expression.getYear(); if (!Objects.equals(year, this.defaultExpression.getYear())) { writer.writeString(startIndex + YEAR_FIELD, year); } String month = expression.getMonth(); if (!Objects.equals(month, this.defaultExpression.getMonth())) { writer.writeString(startIndex + MONTH_FIELD, month); } String dayOfMonth = expression.getDayOfMonth(); if (!Objects.equals(dayOfMonth, this.defaultExpression.getDayOfMonth())) { writer.writeString(startIndex + DAY_OF_MONTH_FIELD, dayOfMonth); } String dayOfWeek = expression.getDayOfWeek(); if (!Objects.equals(dayOfWeek, this.defaultExpression.getDayOfWeek())) { writer.writeString(startIndex + DAY_OF_WEEK_FIELD, dayOfWeek); } ZoneId zone = expression.getZone(); if (!Objects.equals(zone, this.defaultExpression.getZone())) { writer.writeObject(startIndex + ZONE_FIELD, zone); } String hour = expression.getHour(); if (!Objects.equals(hour, this.defaultExpression.getHour())) { writer.writeString(startIndex + HOUR_FIELD, hour); } String minute = expression.getMinute(); if (!Objects.equals(minute, this.defaultExpression.getMinute())) { writer.writeString(startIndex + MINUTE_FIELD, minute); } String second = expression.getSecond(); if (!Objects.equals(second, this.defaultExpression.getSecond())) { writer.writeString(startIndex + SECOND_FIELD, second); } } }
5,833
41.583942
157
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/InfinispanTimerManagementProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.wildfly.clustering.ejb.timer.TimerManagementProvider; import org.wildfly.clustering.ejb.timer.TimerManagerFactoryConfiguration; /** * @author Paul Ferraro */ public class InfinispanTimerManagementProvider implements TimerManagementProvider { private final InfinispanTimerManagementConfiguration configuration; public InfinispanTimerManagementProvider(InfinispanTimerManagementConfiguration configuration) { this.configuration = configuration; } @Override public <I> CapabilityServiceConfigurator getTimerManagerFactoryServiceConfigurator(TimerManagerFactoryConfiguration<I> configuration) { return new InfinispanTimerManagerFactoryServiceConfigurator<>(this.configuration, configuration); } }
1,901
41.266667
139
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/TimerMetaDataCreationContext.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.util.function.BiFunction; import org.wildfly.clustering.ejb.timer.TimerConfiguration; import org.wildfly.clustering.marshalling.spi.MarshalledValue; /** * @author Paul Ferraro */ public interface TimerMetaDataCreationContext<MC> { Object getInfo(); TimerConfiguration getConfiguration(); BiFunction<MarshalledValue<Object, MC>, ? extends TimerConfiguration, TimerCreationMetaData<MC>> getCreationMetaDataFactory(); }
1,526
36.243902
130
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/ScheduleTimerCreationMetaData.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import org.wildfly.clustering.ejb.timer.ScheduleTimerConfiguration; import org.wildfly.clustering.ejb.timer.TimerType; /** * @author Paul Ferraro */ public interface ScheduleTimerCreationMetaData<V> extends TimerCreationMetaData<V>, ScheduleTimerConfiguration { @Override default TimerType getType() { return TimerType.SCHEDULE; } @Override TimeoutDescriptor getTimeoutMatcher(); }
1,493
35.439024
112
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/TimerCreationMetaDataKeyFilter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import org.infinispan.util.function.SerializablePredicate; /** * @author Paul Ferraro */ public enum TimerCreationMetaDataKeyFilter implements SerializablePredicate<Object> { INSTANCE; @Override public boolean test(Object key) { return key instanceof TimerCreationMetaDataKey; } }
1,387
35.526316
85
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/TimerIndex.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.lang.reflect.Method; import java.util.Objects; /** * Index for auto-timers. Ensures auto-timers are only created once across cluster. * @author Paul Ferraro */ public class TimerIndex extends TimeoutDescriptor { private final String declaringClassName; private final int index; public TimerIndex(Method method, int index) { super(method); this.declaringClassName = method.getDeclaringClass().getName(); this.index = index; } public TimerIndex(String declaringClassName, String methodName, int parameters, int index) { super(methodName, parameters); this.declaringClassName = declaringClassName; this.index = index; } @Override public int hashCode() { return Objects.hash(this.declaringClassName, this.getMethodName()) + this.getParameters() + this.index; } @Override public boolean equals(Object object) { if (!(object instanceof TimerIndex)) return false; TimerIndex index = (TimerIndex) object; // We only need to compare method name and parameter count for method equality. return this.declaringClassName.equals(index.declaringClassName) && super.equals(index) && this.index == index.index; } @Override public String toString() { return String.format("%s.%s(%s)[%s]", this.declaringClassName, this.getMethodName(), this.getParameters() > 0 ? "Timer" : "", this.index); } String getDeclaringClassName() { return this.declaringClassName; } int getIndex() { return this.index; } }
2,671
35.108108
146
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/TimerAccessMetaDataKey.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import org.wildfly.clustering.ee.infinispan.GroupedKey; /** * @author Paul Ferraro */ public class TimerAccessMetaDataKey<I> extends GroupedKey<I> { public TimerAccessMetaDataKey(I id) { super(id); } }
1,300
35.138889
70
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/TimerSerializationContextInitializer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.util.UUID; import org.infinispan.protostream.SerializationContext; import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer; import org.wildfly.clustering.marshalling.protostream.EnumMarshaller; import org.wildfly.clustering.marshalling.protostream.FunctionalMarshaller; /** * @author Paul Ferraro */ public class TimerSerializationContextInitializer extends AbstractSerializationContextInitializer { @Override public void registerMarshallers(SerializationContext context) { context.registerMarshaller(new FunctionalMarshaller<>(TimerCreationMetaDataKey.class, UUID.class, TimerCreationMetaDataKey<UUID>::getId, TimerCreationMetaDataKey::new)); context.registerMarshaller(new FunctionalMarshaller<>(TimerAccessMetaDataKey.class, UUID.class, TimerAccessMetaDataKey<UUID>::getId, TimerAccessMetaDataKey::new)); context.registerMarshaller(new IntervalTimerCreationMetaDataMarshaller()); context.registerMarshaller(new ScheduleTimerCreationMetaDataMarshaller()); context.registerMarshaller(new FunctionalMarshaller<>(TimerIndexKey.class, TimerIndexMarshaller.INSTANCE, TimerIndexKey::getId, TimerIndexKey::new)); context.registerMarshaller(new EnumMarshaller<>(TimerCreationMetaDataKeyFilter.class)); } }
2,393
49.93617
177
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/InfinispanTimerManager.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.io.IOException; import java.lang.reflect.Method; import java.time.Duration; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Stream; import org.infinispan.Cache; import org.infinispan.remoting.transport.Address; import org.wildfly.clustering.ee.Batcher; import org.wildfly.clustering.ee.Key; import org.wildfly.clustering.ee.Scheduler; import org.wildfly.clustering.ee.cache.CacheProperties; import org.wildfly.clustering.ee.cache.IdentifierFactory; import org.wildfly.clustering.ee.cache.tx.TransactionBatch; import org.wildfly.clustering.ee.infinispan.PrimaryOwnerLocator; import org.wildfly.clustering.ee.infinispan.affinity.AffinityIdentifierFactory; import org.wildfly.clustering.ee.infinispan.scheduler.PrimaryOwnerScheduler; import org.wildfly.clustering.ee.infinispan.scheduler.ScheduleLocalKeysTask; import org.wildfly.clustering.ee.infinispan.scheduler.ScheduleWithMetaDataCommand; import org.wildfly.clustering.ee.infinispan.scheduler.ScheduleWithTransientMetaDataCommand; import org.wildfly.clustering.ee.infinispan.scheduler.SchedulerTopologyChangeListener; import org.wildfly.clustering.ejb.timer.ImmutableTimerMetaData; import org.wildfly.clustering.ejb.timer.IntervalTimerConfiguration; import org.wildfly.clustering.ejb.timer.ScheduleTimerConfiguration; import org.wildfly.clustering.ejb.timer.Timer; import org.wildfly.clustering.ejb.timer.TimerManager; import org.wildfly.clustering.ejb.timer.TimerRegistry; import org.wildfly.clustering.infinispan.distribution.CacheLocality; import org.wildfly.clustering.infinispan.distribution.Locality; import org.wildfly.clustering.infinispan.distribution.SimpleLocality; import org.wildfly.clustering.infinispan.listener.ListenerRegistration; import org.wildfly.clustering.marshalling.spi.Marshaller; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.server.group.Group; /** * A timer manager backed by an Infinispan cache. * @author Paul Ferraro */ public class InfinispanTimerManager<I, V> implements TimerManager<I, TransactionBatch> { private final Cache<Key<I>, ?> cache; private final CacheProperties properties; private final TimerFactory<I, V> factory; private final Marshaller<Object, V> marshaller; private final IdentifierFactory<I> identifierFactory; private final Batcher<TransactionBatch> batcher; private final CommandDispatcherFactory dispatcherFactory; private final Group<Address> group; private final TimerRegistry<I> registry; private volatile Scheduler<I, ImmutableTimerMetaData> scheduledTimers; private volatile Scheduler<I, ImmutableTimerMetaData> scheduler; private volatile ListenerRegistration schedulerListenerRegistration; public InfinispanTimerManager(InfinispanTimerManagerConfiguration<I, V> config) { this.cache = config.getCache(); this.properties = config.getCacheProperties(); this.marshaller = config.getMarshaller(); this.identifierFactory = new AffinityIdentifierFactory<>(config.getIdentifierFactory(), this.cache, config.getKeyAffinityServiceFactory()); this.batcher = config.getBatcher(); this.dispatcherFactory = config.getCommandDispatcherFactory(); this.group = config.getGroup(); this.factory = config.getTimerFactory(); this.registry = config.getRegistry(); } @Override public void start() { Supplier<Locality> locality = () -> new CacheLocality(this.cache); TimerScheduler<I, V> localScheduler = new TimerScheduler<>(this.factory, this, locality, Duration.ofMillis(this.cache.getCacheConfiguration().transaction().cacheStopTimeout()), this.registry); this.scheduledTimers = localScheduler; this.scheduler = this.group.isSingleton() ? localScheduler : new PrimaryOwnerScheduler<>(this.dispatcherFactory, this.cache.getName(), localScheduler, new PrimaryOwnerLocator<>(this.cache, this.group), TimerCreationMetaDataKey::new, this.properties.isTransactional() ? ScheduleWithMetaDataCommand::new : ScheduleWithTransientMetaDataCommand::new); TimerRegistry<I> registry = this.registry; BiConsumer<Locality, Locality> scheduleTask = new ScheduleLocalKeysTask<>(this.cache, TimerCreationMetaDataKeyFilter.INSTANCE, new Consumer<I>() { @Override public void accept(I id) { localScheduler.schedule(id); registry.register(id); } }); this.schedulerListenerRegistration = new SchedulerTopologyChangeListener<>(this.cache, localScheduler, scheduleTask).register(); scheduleTask.accept(new SimpleLocality(false), new CacheLocality(this.cache)); this.identifierFactory.start(); } @Override public void stop() { this.identifierFactory.stop(); ListenerRegistration registration = this.schedulerListenerRegistration; if (registration != null) { registration.close(); } Scheduler<I, ImmutableTimerMetaData> scheduler = this.scheduler; if (scheduler != null) { scheduler.close(); } } @Override public Timer<I> createTimer(I id, IntervalTimerConfiguration config, Object context) { try { TimerCreationMetaData<V> creationMetaData = new IntervalTimerCreationMetaDataEntry<>(this.marshaller.write(context), config); return this.createTimer(id, creationMetaData, (TimerIndex) null); } catch (IOException e) { throw new IllegalStateException(e); } } @Override public Timer<I> createTimer(I id, ScheduleTimerConfiguration config, Object context) { try { TimerCreationMetaData<V> creationMetaData = new ScheduleTimerCreationMetaDataEntry<>(this.marshaller.write(context), config, null); return this.createTimer(id, creationMetaData, (TimerIndex) null); } catch (IOException e) { throw new IllegalStateException(e); } } @Override public Timer<I> createTimer(I id, ScheduleTimerConfiguration config, Object context, Method method, int index) { try { TimerCreationMetaData<V> creationMetaData = new ScheduleTimerCreationMetaDataEntry<>(this.marshaller.write(context), config, method); return this.createTimer(id, creationMetaData, new TimerIndex(method, index)); } catch (IOException e) { throw new IllegalStateException(e); } } private Timer<I> createTimer(I id, TimerCreationMetaData<V> creationMetaData, TimerIndex index) { TimerMetaDataFactory<I, V> metaDataFactory = this.factory.getMetaDataFactory(); Map.Entry<TimerCreationMetaData<V>, TimerAccessMetaData> entry = metaDataFactory.createValue(id, new SimpleImmutableEntry<>(creationMetaData, index)); if (entry == null) return null; // Timer with index already exists ImmutableTimerMetaData metaData = metaDataFactory.createImmutableTimerMetaData(entry); Timer<I> timer = this.factory.createTimer(id, metaData, this, this.scheduledTimers); return timer; } @Override public Timer<I> getTimer(I id) { ImmutableTimerMetaDataFactory<I, V> metaDataFactory = this.factory.getMetaDataFactory(); Map.Entry<TimerCreationMetaData<V>, TimerAccessMetaData> entry = metaDataFactory.findValue(id); if (entry != null) { ImmutableTimerMetaData metaData = metaDataFactory.createImmutableTimerMetaData(entry); return this.factory.createTimer(id, metaData, this, this.scheduledTimers); } return null; } @Override public Stream<I> getActiveTimers() { // The primary owner scheduler can miss entries, if called during a concurrent topology change event return this.group.isSingleton() ? this.scheduledTimers.stream() : this.cache.keySet().stream().filter(TimerCreationMetaDataKeyFilter.INSTANCE).map(Key::getId); } @Override public Supplier<I> getIdentifierFactory() { return this.identifierFactory; } @Override public Batcher<TransactionBatch> getBatcher() { return this.batcher; } @Override public String toString() { return this.cache.getName(); } }
9,512
44.735577
355
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/InfinispanTimer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import org.wildfly.clustering.ejb.timer.Timer; import org.wildfly.clustering.ejb.timer.TimerManager; import org.wildfly.clustering.ejb.timer.TimerRegistry; import org.wildfly.clustering.ee.Remover; import org.wildfly.clustering.ee.Scheduler; import org.wildfly.clustering.ee.cache.tx.TransactionBatch; import org.wildfly.clustering.ejb.timer.ImmutableTimerMetaData; import org.wildfly.clustering.ejb.timer.TimeoutListener; /** * @author Paul Ferraro */ public class InfinispanTimer<I> implements Timer<I> { private final TimerManager<I, TransactionBatch> manager; private final I id; private final ImmutableTimerMetaData metaData; private final Scheduler<I, ImmutableTimerMetaData> scheduler; private final TimeoutListener<I, TransactionBatch> listener; private final Remover<I> remover; private final TimerRegistry<I> registry; private volatile boolean canceled = false; public InfinispanTimer(TimerManager<I, TransactionBatch> manager, I id, ImmutableTimerMetaData metaData, Scheduler<I, ImmutableTimerMetaData> scheduler, TimeoutListener<I, TransactionBatch> listener, Remover<I> remover, TimerRegistry<I> registry) { this.manager = manager; this.id = id; this.metaData = metaData; this.scheduler = scheduler; this.listener = listener; this.remover = remover; this.registry = registry; } @Override public I getId() { return this.id; } @Override public ImmutableTimerMetaData getMetaData() { return this.metaData; } @Override public boolean isActive() { return this.scheduler.contains(this.id); } @Override public boolean isCanceled() { return this.canceled; } @Override public void cancel() { this.suspend(); this.remove(); this.canceled = true; } private void remove() { this.registry.unregister(this.id); this.remover.remove(this.id); } @Override public void invoke() throws Exception { this.listener.timeout(this.manager, this); } @Override public void suspend() { this.scheduler.cancel(this.id); } @Override public void activate() { if (!this.isActive()) { this.scheduler.schedule(this.id, this.metaData); } } @Override public int hashCode() { return this.id.hashCode(); } @Override public boolean equals(Object object) { if (!(object instanceof Timer)) return false; return this.id.equals(((Timer<?>) object).getId()); } @Override public String toString() { return this.id.toString(); } }
3,777
29.467742
252
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/timer/IntervalTimerCreationMetaDataEntry.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.timer; import java.time.Duration; import java.time.Instant; import org.wildfly.clustering.ejb.timer.IntervalTimerConfiguration; /** * @author Paul Ferraro */ public class IntervalTimerCreationMetaDataEntry<V> extends AbstractTimerCreationMetaDataEntry<V> implements IntervalTimerCreationMetaData<V> { private final Duration interval; public IntervalTimerCreationMetaDataEntry(V context, IntervalTimerConfiguration config) { this(context, config.getStart(), config.getInterval()); } public IntervalTimerCreationMetaDataEntry(V context, Instant start, Duration interval) { super(context, start); this.interval = interval; } @Override public Duration getInterval() { return this.interval; } @Override public Instant apply(Instant lastTimeout) { return (lastTimeout == null) ? this.getStart() : (this.interval != null) ? lastTimeout.plus(this.interval) : null; } }
2,025
35.178571
142
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanManagerFactoryServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.util.function.Consumer; import org.infinispan.Cache; import org.infinispan.remoting.transport.Address; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.ee.cache.tx.TransactionBatch; import org.wildfly.clustering.ejb.bean.BeanConfiguration; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.bean.BeanManagerFactory; import org.wildfly.clustering.ejb.bean.BeanPassivationConfiguration; import org.wildfly.clustering.ejb.cache.bean.BeanGroupManager; import org.wildfly.clustering.ejb.cache.bean.BeanGroupManagerServiceNameProvider; import org.wildfly.clustering.infinispan.affinity.KeyAffinityServiceFactory; import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement; import org.wildfly.clustering.infinispan.service.InfinispanRequirement; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.server.group.Group; import org.wildfly.clustering.server.service.ClusteringCacheRequirement; import org.wildfly.clustering.server.service.ClusteringRequirement; import org.wildfly.clustering.service.CompositeDependency; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; /** * Configures a service that provides an Infinispan-based {@link BeanManagerFactory}. * @author Paul Ferraro * @param <K> the bean identifier type * @param <V> the bean instance type */ public class InfinispanBeanManagerFactoryServiceConfigurator<K, V extends BeanInstance<K>> extends SimpleServiceNameProvider implements CapabilityServiceConfigurator, InfinispanBeanManagerFactoryConfiguration<K, V> { private final String cacheName; private final BeanConfiguration beanConfiguration; private final InfinispanBeanManagementConfiguration configuration; private final SupplierDependency<BeanGroupManager<K, V>> groupManager; private volatile SupplierDependency<Cache<?, ?>> cache; private volatile SupplierDependency<KeyAffinityServiceFactory> affinityFactory; private volatile SupplierDependency<Group<Address>> group; private volatile SupplierDependency<CommandDispatcherFactory> dispatcherFactory; public InfinispanBeanManagerFactoryServiceConfigurator(BeanConfiguration beanConfiguration, InfinispanBeanManagementConfiguration configuration) { super(beanConfiguration.getDeploymentServiceName().append(beanConfiguration.getName()).append("bean-manager")); this.beanConfiguration = beanConfiguration; this.configuration = configuration; this.cacheName = beanConfiguration.getDeploymentName(); this.groupManager = new ServiceSupplierDependency<>(new BeanGroupManagerServiceNameProvider(beanConfiguration)); } @Override public ServiceConfigurator configure(CapabilityServiceSupport support) { String containerName = this.configuration.getContainerName(); this.cache = new ServiceSupplierDependency<>(InfinispanCacheRequirement.CACHE.getServiceName(support, containerName, this.cacheName)); this.affinityFactory = new ServiceSupplierDependency<>(InfinispanRequirement.KEY_AFFINITY_FACTORY.getServiceName(support, containerName)); this.dispatcherFactory = new ServiceSupplierDependency<>(ClusteringRequirement.COMMAND_DISPATCHER_FACTORY.getServiceName(support, containerName)); this.group = new ServiceSupplierDependency<>(ClusteringCacheRequirement.GROUP.getServiceName(support, containerName, this.cacheName)); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); new CompositeDependency(this.cache, this.affinityFactory, this.group, this.dispatcherFactory, this.groupManager).register(builder); Consumer<BeanManagerFactory<K, V, TransactionBatch>> factory = builder.provides(this.getServiceName()); Service service = Service.newInstance(factory, new InfinispanBeanManagerFactory<>(this)); return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND); } @Override public BeanConfiguration getBeanConfiguration() { return this.beanConfiguration; } @SuppressWarnings("unchecked") @Override public <KK, VV> Cache<KK, VV> getCache() { return (Cache<KK, VV>) this.cache.get(); } @Override public KeyAffinityServiceFactory getKeyAffinityServiceFactory() { return this.affinityFactory.get(); } @Override public BeanPassivationConfiguration getPassivationConfiguration() { return this.configuration; } @Override public Group<Address> getGroup() { return this.group.get(); } @Override public CommandDispatcherFactory getCommandDispatcherFactory() { return this.dispatcherFactory.get(); } @Override public BeanGroupManager<K, V> getBeanGroupManager() { return this.groupManager.get(); } }
6,500
46.452555
216
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanManagementProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.util.List; import java.util.function.Consumer; import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.configuration.cache.ExpirationConfiguration; import org.infinispan.configuration.cache.StorageType; import org.infinispan.eviction.EvictionStrategy; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.as.clustering.controller.FunctionalCapabilityServiceConfigurator; import org.jboss.as.controller.ServiceNameFactory; import org.wildfly.clustering.ejb.bean.BeanConfiguration; import org.wildfly.clustering.ejb.bean.BeanDeploymentConfiguration; import org.wildfly.clustering.ejb.bean.BeanManagementProvider; import org.wildfly.clustering.ejb.bean.BeanManagerFactory; import org.wildfly.clustering.ejb.infinispan.logging.InfinispanEjbLogger; import org.wildfly.clustering.infinispan.container.DataContainerConfigurationBuilder; import org.wildfly.clustering.infinispan.service.CacheServiceConfigurator; import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement; import org.wildfly.clustering.infinispan.service.TemplateConfigurationServiceConfigurator; import org.wildfly.clustering.server.service.ProvidedCacheServiceConfigurator; import org.wildfly.clustering.server.service.group.DistributedCacheGroupServiceConfiguratorProvider; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.common.function.Functions; /** * Builds an infinispan-based {@link BeanManagerFactory}. * * @author Paul Ferraro */ public class InfinispanBeanManagementProvider implements BeanManagementProvider { private final String name; private final InfinispanBeanManagementConfiguration config; public InfinispanBeanManagementProvider(String name, InfinispanBeanManagementConfiguration config) { this.name = name; this.config = config; } @Override public String getName() { return this.name; } @Override public Iterable<CapabilityServiceConfigurator> getDeploymentServiceConfigurators(BeanDeploymentConfiguration configuration) { String containerName = this.config.getContainerName(); String templateCacheName = this.config.getCacheName(); String cacheName = configuration.getDeploymentName(); // Ensure eviction and expiration are disabled Consumer<ConfigurationBuilder> configurator = builder -> { // Ensure expiration is not enabled on cache ExpirationConfiguration expiration = builder.expiration().create(); if ((expiration.lifespan() >= 0) || (expiration.maxIdle() >= 0)) { builder.expiration().lifespan(-1).maxIdle(-1); InfinispanEjbLogger.ROOT_LOGGER.expirationDisabled(InfinispanCacheRequirement.CONFIGURATION.resolve(containerName, templateCacheName)); } Integer size = this.config.getMaxActiveBeans(); EvictionStrategy strategy = (size != null) ? EvictionStrategy.REMOVE : EvictionStrategy.MANUAL; builder.memory().storage(StorageType.HEAP).whenFull(strategy).maxCount((size != null) ? size.longValue() : 0); if (strategy.isEnabled()) { // Only evict bean group entries // We will cascade eviction to the associated beans builder.addModule(DataContainerConfigurationBuilder.class).evictable(InfinispanBeanGroupKey.class::isInstance); } }; CapabilityServiceConfigurator configurationConfigurator = new TemplateConfigurationServiceConfigurator(ServiceNameFactory.parseServiceName(InfinispanCacheRequirement.CONFIGURATION.getName()).append(containerName, cacheName), containerName, cacheName, templateCacheName, configurator); CapabilityServiceConfigurator cacheConfigurator = new CacheServiceConfigurator<>(ServiceNameFactory.parseServiceName(InfinispanCacheRequirement.CACHE.getName()).append(containerName, cacheName), containerName, cacheName); CapabilityServiceConfigurator groupConfigurator = new ProvidedCacheServiceConfigurator<>(DistributedCacheGroupServiceConfiguratorProvider.class, containerName, cacheName); CapabilityServiceConfigurator marshallerConfigurator = new FunctionalCapabilityServiceConfigurator<>(configuration.getDeploymentServiceName().append(this.name, "marshaller"), this.config.getMarshallerFactory(), Functions.constantSupplier(configuration)); CapabilityServiceConfigurator groupManagerConfigurator = new InfinispanBeanGroupManagerServiceConfigurator<>(configuration, new ServiceSupplierDependency<>(cacheConfigurator), new ServiceSupplierDependency<>(marshallerConfigurator)); CapabilityServiceConfigurator groupListenerConfigurator = new InfinispanBeanGroupListenerServiceConfigurator<>(cacheConfigurator.getServiceName().append("listener"), new ServiceSupplierDependency<>(cacheConfigurator), new ServiceSupplierDependency<>(marshallerConfigurator)); return List.of(configurationConfigurator, cacheConfigurator, groupConfigurator, marshallerConfigurator, groupManagerConfigurator, groupListenerConfigurator); } @Override public CapabilityServiceConfigurator getBeanManagerFactoryServiceConfigurator(BeanConfiguration context) { return new InfinispanBeanManagerFactoryServiceConfigurator<>(context, this.config); } }
6,431
59.11215
292
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanManagerConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.infinispan.remoting.transport.Address; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.cache.bean.BeanManagerConfiguration; import org.wildfly.clustering.infinispan.affinity.KeyAffinityServiceFactory; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.server.group.Group; /** * Encapsulates the configuration of an {@link InfinispanBeanManager}. * @author Paul Ferraro * @param <K> the bean identifier type * @param <V> the bean instance type * @param <M> the bean metadata value type */ public interface InfinispanBeanManagerConfiguration<K, V extends BeanInstance<K>, M> extends BeanManagerConfiguration<K, V, M>, InfinispanBeanMetaDataFactoryConfiguration { @Override Group<Address> getGroup(); KeyAffinityServiceFactory getAffinityFactory(); CommandDispatcherFactory getCommandDispatcherFactory(); }
2,002
45.581395
172
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanMetaDataFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.util.Map; import org.infinispan.Cache; import org.wildfly.clustering.ee.Key; import org.wildfly.clustering.ee.Mutator; import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.infinispan.InfinispanMutatorFactory; import org.wildfly.clustering.ejb.bean.BeanExpiration; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.bean.BeanMetaData; import org.wildfly.clustering.ejb.bean.ImmutableBeanMetaData; import org.wildfly.clustering.ejb.cache.bean.BeanAccessMetaData; import org.wildfly.clustering.ejb.cache.bean.BeanAccessMetaDataKey; import org.wildfly.clustering.ejb.cache.bean.BeanCreationMetaData; import org.wildfly.clustering.ejb.cache.bean.BeanCreationMetaDataKey; import org.wildfly.clustering.ejb.cache.bean.BeanMetaDataFactory; import org.wildfly.clustering.ejb.cache.bean.CompositeBeanMetaData; import org.wildfly.clustering.ejb.cache.bean.CompositeImmutableBeanMetaData; import org.wildfly.clustering.ejb.cache.bean.ImmortalBeanAccessMetaData; import org.wildfly.clustering.ejb.cache.bean.MutableBeanAccessMetaData; import org.wildfly.clustering.ejb.cache.bean.SimpleBeanAccessMetaData; import org.wildfly.clustering.ejb.cache.bean.SimpleBeanCreationMetaData; /** * A {@link BeanMetaDataFactory} whose metadata entries are stored in an embedded Infinispan cache. * @author Paul Ferraro * @param <K> the bean identifier type */ public class InfinispanBeanMetaDataFactory<K> implements BeanMetaDataFactory<K, Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData>> { private final Cache<Key<K>, Object> writeOnlyCache; private final Cache<BeanCreationMetaDataKey<K>, BeanCreationMetaData<K>> creationMetaDataReadForUpdateCache; private final Cache<BeanCreationMetaDataKey<K>, BeanCreationMetaData<K>> creationMetaDataTryReadForUpdateCache; private final Cache<BeanAccessMetaDataKey<K>, BeanAccessMetaData> accessMetaDataCache; private final MutatorFactory<BeanAccessMetaDataKey<K>, BeanAccessMetaData> mutatorFactory; private final BeanExpiration expiration; private final String beanName; public InfinispanBeanMetaDataFactory(InfinispanBeanMetaDataFactoryConfiguration configuration) { this.writeOnlyCache = configuration.getWriteOnlyCache(); this.creationMetaDataReadForUpdateCache = configuration.getReadForUpdateCache(); this.creationMetaDataTryReadForUpdateCache = configuration.getTryReadForUpdateCache(); this.expiration = configuration.getExpiration(); boolean scheduledExpiration = (this.expiration != null) && !this.expiration.getTimeout().isZero(); this.accessMetaDataCache = scheduledExpiration ? configuration.getCache() : null; this.mutatorFactory = (this.accessMetaDataCache != null) ? new InfinispanMutatorFactory<>(this.accessMetaDataCache) : null; this.beanName = configuration.getBeanName(); } @Override public Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData> createValue(BeanInstance<K> instance, K groupId) { K id = instance.getId(); BeanCreationMetaDataKey<K> creationMetaDataKey = new InfinispanBeanCreationMetaDataKey<>(id); BeanCreationMetaData<K> creationMetaData = new SimpleBeanCreationMetaData<>(this.beanName, groupId); BeanAccessMetaData accessMetaData = (this.accessMetaDataCache != null) ? new SimpleBeanAccessMetaData() : ImmortalBeanAccessMetaData.INSTANCE; if (this.accessMetaDataCache != null) { BeanAccessMetaDataKey<K> accessMetaDataKey = new InfinispanBeanAccessMetaDataKey<>(id); this.writeOnlyCache.putAll(Map.of(creationMetaDataKey, creationMetaData, accessMetaDataKey, accessMetaData)); } else { this.writeOnlyCache.put(creationMetaDataKey, creationMetaData); } return Map.entry(creationMetaData, accessMetaData); } @Override public Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData> findValue(K id) { return this.getValue(this.creationMetaDataReadForUpdateCache, id); } @Override public Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData> tryValue(K id) { return this.getValue(this.creationMetaDataTryReadForUpdateCache, id); } private Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData> getValue(Cache<BeanCreationMetaDataKey<K>, BeanCreationMetaData<K>> creationMetaDataCache, K id) { BeanCreationMetaData<K> creationMetaData = creationMetaDataCache.get(new InfinispanBeanCreationMetaDataKey<>(id)); if (creationMetaData == null) return null; BeanAccessMetaData accessMetaData = (this.accessMetaDataCache != null) ? this.accessMetaDataCache.get(new InfinispanBeanAccessMetaDataKey<>(id)) : null; return Map.entry(creationMetaData, (accessMetaData != null) ? accessMetaData : ImmortalBeanAccessMetaData.INSTANCE); } @Override public boolean remove(K id) { this.writeOnlyCache.remove(new InfinispanBeanCreationMetaDataKey<>(id)); if (this.accessMetaDataCache != null) { this.writeOnlyCache.remove(new InfinispanBeanAccessMetaDataKey<>(id)); } return true; } @Override public ImmutableBeanMetaData<K> createImmutableBeanMetaData(K id, Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData> entry) { BeanCreationMetaData<K> creationMetaData = entry.getKey(); BeanAccessMetaData accessMetaData = entry.getValue(); return new CompositeImmutableBeanMetaData<>(creationMetaData, accessMetaData, this.expiration); } @Override public BeanMetaData<K> createBeanMetaData(K id, Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData> entry) { BeanCreationMetaData<K> creationMetaData = entry.getKey(); BeanAccessMetaData accessMetaData = entry.getValue(); Mutator mutator = (this.mutatorFactory != null) ? this.mutatorFactory.createMutator(new InfinispanBeanAccessMetaDataKey<>(id), accessMetaData) : Mutator.PASSIVE; return new CompositeBeanMetaData<>(creationMetaData, (mutator != Mutator.PASSIVE) ? new MutableBeanAccessMetaData(accessMetaData, mutator) : accessMetaData, this.expiration); } }
7,247
54.753846
182
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanManagerFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.util.Map; import java.util.function.Supplier; import org.infinispan.Cache; import org.infinispan.remoting.transport.Address; import org.wildfly.clustering.ee.cache.tx.TransactionBatch; import org.wildfly.clustering.ejb.bean.BeanExpirationConfiguration; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.bean.BeanManager; import org.wildfly.clustering.ejb.bean.BeanManagerConfiguration; import org.wildfly.clustering.ejb.bean.BeanManagerFactory; import org.wildfly.clustering.ejb.cache.bean.BeanAccessMetaData; import org.wildfly.clustering.ejb.cache.bean.BeanCreationMetaData; import org.wildfly.clustering.ejb.cache.bean.BeanFactory; import org.wildfly.clustering.ejb.cache.bean.CompositeBeanFactory; import org.wildfly.clustering.infinispan.affinity.KeyAffinityServiceFactory; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.server.group.Group; /** * Factory for creating an infinispan-based {@link BeanManager}. * @author Paul Ferraro * @param <K> the bean identifier type * @param <V> the bean instance type */ public class InfinispanBeanManagerFactory<K, V extends BeanInstance<K>> implements BeanManagerFactory<K, V, TransactionBatch> { private final InfinispanBeanManagerFactoryConfiguration<K, V> configuration; public InfinispanBeanManagerFactory(InfinispanBeanManagerFactoryConfiguration<K, V> configuration) { this.configuration = configuration; } @Override public BeanManager<K, V, TransactionBatch> createBeanManager(BeanManagerConfiguration<K, V> configuration) { return new InfinispanBeanManager<>(new DefaultInfinispanBeanManagerConfiguration<>(this.configuration, configuration)); } private static class DefaultInfinispanBeanManagerConfiguration<K, V extends BeanInstance<K>> implements InfinispanBeanManagerConfiguration<K, V, Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData>> { private final InfinispanBeanManagerFactoryConfiguration<K, V> factoryConfiguration; private final BeanManagerConfiguration<K, V> managerConfiguration; private final BeanFactory<K, V, Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData>> beanFactory; DefaultInfinispanBeanManagerConfiguration(InfinispanBeanManagerFactoryConfiguration<K, V> factoryConfiguration, BeanManagerConfiguration<K, V> managerConfiguration) { this.factoryConfiguration = factoryConfiguration; this.managerConfiguration = managerConfiguration; this.beanFactory = new CompositeBeanFactory<>(new InfinispanBeanMetaDataFactory<>(this), factoryConfiguration.getBeanGroupManager()); } @Override public BeanExpirationConfiguration<K, V> getExpiration() { return this.managerConfiguration.getExpiration(); } @Override public String getBeanName() { return this.managerConfiguration.getBeanName(); } @Override public <KK, VV> Cache<KK, VV> getCache() { return this.factoryConfiguration.getCache(); } @Override public BeanFactory<K, V, Map.Entry<BeanCreationMetaData<K>, BeanAccessMetaData>> getBeanFactory() { return this.beanFactory; } @Override public Supplier<K> getIdentifierFactory() { return this.managerConfiguration.getIdentifierFactory(); } @Override public KeyAffinityServiceFactory getAffinityFactory() { return this.factoryConfiguration.getKeyAffinityServiceFactory(); } @Override public Group<Address> getGroup() { return this.factoryConfiguration.getGroup(); } @Override public CommandDispatcherFactory getCommandDispatcherFactory() { return this.factoryConfiguration.getCommandDispatcherFactory(); } } }
5,001
42.877193
206
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanManagerFactoryConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.infinispan.remoting.transport.Address; import org.wildfly.clustering.ee.infinispan.InfinispanConfiguration; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.cache.bean.BeanManagerFactoryConfiguration; import org.wildfly.clustering.infinispan.affinity.KeyAffinityServiceFactory; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.server.group.Group; /** * Encapsulates the configuration for an {@link InfinispanBeanManagerFactory}. * @author Paul Ferraro * @param <K> the bean identifier type * @param <V> the bean instance type */ public interface InfinispanBeanManagerFactoryConfiguration<K, V extends BeanInstance<K>> extends BeanManagerFactoryConfiguration<K, V>, InfinispanConfiguration { KeyAffinityServiceFactory getKeyAffinityServiceFactory(); @Override Group<Address> getGroup(); CommandDispatcherFactory getCommandDispatcherFactory(); }
2,043
45.454545
161
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanSerializationContextInitializer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.infinispan.protostream.SerializationContext; import org.jboss.ejb.client.SessionID; import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer; import org.wildfly.clustering.marshalling.protostream.FunctionalMarshaller; /** * A {@link SerializationContextInitializer} that registers marshallers for types in this package. * @author Paul Ferraro */ public class InfinispanBeanSerializationContextInitializer extends AbstractSerializationContextInitializer { @SuppressWarnings("unchecked") @Override public void registerMarshallers(SerializationContext context) { context.registerMarshaller(new FunctionalMarshaller<>((Class<InfinispanBeanCreationMetaDataKey<SessionID>>) (Class<?>) InfinispanBeanCreationMetaDataKey.class, SessionID.class, InfinispanBeanCreationMetaDataKey::getId, InfinispanBeanCreationMetaDataKey::new)); context.registerMarshaller(new FunctionalMarshaller<>((Class<InfinispanBeanAccessMetaDataKey<SessionID>>) (Class<?>) InfinispanBeanAccessMetaDataKey.class, SessionID.class, InfinispanBeanAccessMetaDataKey::getId, InfinispanBeanAccessMetaDataKey::new)); context.registerMarshaller(new FunctionalMarshaller<>((Class<InfinispanBeanGroupKey<SessionID>>) (Class<?>) InfinispanBeanGroupKey.class, SessionID.class, InfinispanBeanGroupKey::getId, InfinispanBeanGroupKey::new)); } }
2,465
55.045455
268
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/BeanExpirationScheduler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.time.Duration; import java.util.function.Consumer; import java.util.function.Predicate; import org.wildfly.clustering.ee.Batch; import org.wildfly.clustering.ee.Batcher; import org.wildfly.clustering.ee.cache.scheduler.LinkedScheduledEntries; import org.wildfly.clustering.ee.cache.scheduler.LocalScheduler; import org.wildfly.clustering.ee.cache.scheduler.SortedScheduledEntries; import org.wildfly.clustering.ee.cache.tx.TransactionBatch; import org.wildfly.clustering.ee.infinispan.expiration.AbstractExpirationScheduler; import org.wildfly.clustering.ejb.bean.Bean; import org.wildfly.clustering.ejb.bean.BeanExpirationConfiguration; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.bean.ImmutableBeanMetaData; import org.wildfly.clustering.ejb.cache.bean.BeanFactory; import org.wildfly.clustering.ejb.cache.bean.ImmutableBeanMetaDataFactory; import org.wildfly.clustering.ejb.infinispan.logging.InfinispanEjbLogger; import org.wildfly.clustering.group.Group; /** * Schedules a bean for expiration. * @author Paul Ferraro * @param <K> the bean identifier type * @param <V> the bean instance type * @param <M> the metadata value type */ public class BeanExpirationScheduler<K, V extends BeanInstance<K>, M> extends AbstractExpirationScheduler<K> { private final ImmutableBeanMetaDataFactory<K, M> factory; public BeanExpirationScheduler(Group group, Batcher<TransactionBatch> batcher, BeanFactory<K, V, M> factory, BeanExpirationConfiguration<K, V> expiration, Duration closeTimeout) { super(new LocalScheduler<>(group.isSingleton() ? new LinkedScheduledEntries<>() : new SortedScheduledEntries<>(), new BeanRemoveTask<>(batcher, factory, expiration.getExpirationListener()), closeTimeout)); this.factory = factory.getMetaDataFactory(); } @Override public void schedule(K id) { M value = this.factory.findValue(id); if (value != null) { ImmutableBeanMetaData<K> metaData = this.factory.createImmutableBeanMetaData(id, value); this.schedule(id, metaData); } } private static class BeanRemoveTask<K, V extends BeanInstance<K>, M> implements Predicate<K> { private final Batcher<TransactionBatch> batcher; private final BeanFactory<K, V, M> factory; private final Consumer<V> timeoutListener; BeanRemoveTask(Batcher<TransactionBatch> batcher, BeanFactory<K, V, M> factory, Consumer<V> timeoutListener) { this.batcher = batcher; this.timeoutListener = timeoutListener; this.factory = factory; } @Override public boolean test(K id) { InfinispanEjbLogger.ROOT_LOGGER.tracef("Expiring stateful session bean %s", id); try (Batch batch = this.batcher.createBatch()) { try { M value = this.factory.tryValue(id); if (value != null) { try (Bean<K, V> bean = this.factory.createBean(id, value)) { // Ensure bean is actually expired if (bean.getMetaData().isExpired()) { bean.remove(this.timeoutListener); } } } return true; } catch (RuntimeException e) { batch.discard(); throw e; } } catch (RuntimeException e) { InfinispanEjbLogger.ROOT_LOGGER.failedToExpireBean(e, id); return false; } } } }
4,734
43.669811
213
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanLegacyBeanManagementProviderFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.util.function.Function; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.ejb.bean.BeanManagementProvider; import org.wildfly.clustering.ejb.bean.BeanDeploymentMarshallingContext; import org.wildfly.clustering.ejb.bean.LegacyBeanManagementConfiguration; import org.wildfly.clustering.ejb.bean.LegacyBeanManagementProviderFactory; import org.wildfly.clustering.ejb.cache.bean.BeanMarshallerFactory; import org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller; /** * A {@link LegacyBeanManagementProviderFactory} implementation that creates a suitable {@link BeanManagementProvider} when no distributable-ejb subsystem is present. * @author Paul Ferraro * @deprecated This exists to support legacy configuration that does not define a distributable-ejb subsystem. */ @Deprecated @MetaInfServices(LegacyBeanManagementProviderFactory.class) public class InfinispanLegacyBeanManagementProviderFactory implements LegacyBeanManagementProviderFactory { @Override public BeanManagementProvider createBeanManagementProvider(String name, LegacyBeanManagementConfiguration config) { return new InfinispanBeanManagementProvider(name, new InfinispanBeanManagementConfiguration() { @Override public String getContainerName() { return config.getContainerName(); } @Override public String getCacheName() { return config.getCacheName(); } @Override public Integer getMaxActiveBeans() { return config.getMaxActiveBeans(); } @Override public Function<BeanDeploymentMarshallingContext, ByteBufferMarshaller> getMarshallerFactory() { return BeanMarshallerFactory.JBOSS; } }); } }
2,915
41.882353
166
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanCreationMetaDataKey.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.wildfly.clustering.ee.infinispan.GroupedKey; import org.wildfly.clustering.ejb.cache.bean.BeanCreationMetaDataKey; /** * The key used to cache the creation metadata of a bean. * @author Paul Ferraro * @param <K> the bean identifier type */ public class InfinispanBeanCreationMetaDataKey<K> extends GroupedKey<K> implements BeanCreationMetaDataKey<K> { public InfinispanBeanCreationMetaDataKey(K id) { super(id); } }
1,526
38.153846
111
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanGroupListenerServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; import org.infinispan.Cache; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.wildfly.clustering.ee.Key; import org.wildfly.clustering.ee.infinispan.InfinispanConfiguration; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.cache.bean.BeanCreationMetaDataKey; import org.wildfly.clustering.ejb.cache.bean.BeanGroupKey; import org.wildfly.clustering.ejb.infinispan.logging.InfinispanEjbLogger; import org.wildfly.clustering.infinispan.listener.ListenerRegistration; import org.wildfly.clustering.infinispan.listener.PostActivateBlockingListener; import org.wildfly.clustering.infinispan.listener.PostPassivateBlockingListener; import org.wildfly.clustering.infinispan.listener.PrePassivateBlockingListener; import org.wildfly.clustering.marshalling.spi.MarshalledValue; import org.wildfly.clustering.service.AsyncServiceConfigurator; import org.wildfly.clustering.service.CompositeDependency; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; /** * Cache listener for bean group activation/passivation events. * @author Paul Ferraro * @param <K> the bean identifier type * @param <V> the bean instance type * @param <C> the marshalled value context type */ public class InfinispanBeanGroupListenerServiceConfigurator<K, V extends BeanInstance<K>, C> extends SimpleServiceNameProvider implements CapabilityServiceConfigurator, Service, InfinispanConfiguration { private final SupplierDependency<Cache<?, ?>> cache; private final SupplierDependency<C> context; private volatile Executor executor; private volatile ListenerRegistration postActivateListenerRegistration; private volatile ListenerRegistration prePassivateListenerRegistration; private volatile ListenerRegistration postPassivateListenerRegistration; InfinispanBeanGroupListenerServiceConfigurator(ServiceName name, SupplierDependency<Cache<?, ?>> cache, SupplierDependency<C> context) { super(name); this.cache = cache; this.context = context; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = new AsyncServiceConfigurator(this.getServiceName()).build(target); new CompositeDependency(this.context, this.cache).register(builder); return builder.setInstance(this); } @Override public void start(StartContext context) throws StartException { // We only need to listen for activation/passivation events for non-persistent caches // pre-passivate/post-activate callbacks for persistent caches are triggered via GroupManager if (!this.getCacheProperties().isPersistent()) { this.executor = this.getBlockingManager().asExecutor(this.getClass().getName()); this.postActivateListenerRegistration = new PostActivateBlockingListener<>(this.getCache(), this::postActivate).register(BeanGroupKey.class); this.prePassivateListenerRegistration = new PrePassivateBlockingListener<>(this.getCache(), this::prePassivate).register(BeanGroupKey.class); this.postPassivateListenerRegistration = new PostPassivateBlockingListener<>(this.getCache(), this::cascadeEvict).register(BeanCreationMetaDataKey.class); } } @Override public void stop(StopContext context) { if (this.executor != null) { this.postPassivateListenerRegistration.close(); this.prePassivateListenerRegistration.close(); this.postActivateListenerRegistration.close(); } } void postActivate(BeanGroupKey<K> key, MarshalledValue<Map<K, V>, C> value) { C context = this.context.get(); InfinispanEjbLogger.ROOT_LOGGER.tracef("Received post-activate event for bean group %s", key.getId()); try { Map<K, V> instances = value.get(context); for (V instance : instances.values()) { InfinispanEjbLogger.ROOT_LOGGER.tracef("Invoking post-activate callback for bean %s", instance.getId()); instance.postActivate(); } } catch (IOException e) { InfinispanEjbLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } } void prePassivate(BeanGroupKey<K> key, MarshalledValue<Map<K, V>, C> value) { C context = this.context.get(); InfinispanEjbLogger.ROOT_LOGGER.tracef("Received pre-passivate event for bean group %s", key.getId()); @SuppressWarnings("unchecked") Cache<Key<K>, ?> cache = (Cache<Key<K>, ?>) this.cache.get(); try { Map<K, V> instances = value.get(context); List<V> passivated = new ArrayList<>(instances.size()); try { for (V instance : instances.values()) { K id = instance.getId(); InfinispanEjbLogger.ROOT_LOGGER.tracef("Invoking pre-passivate callback for bean %s", id); instance.prePassivate(); passivated.add(instance); // Cascade eviction to creation meta data entry this.executor.execute(() -> cache.evict(new InfinispanBeanCreationMetaDataKey<>(id))); } } catch (RuntimeException | Error e) { // Restore state of pre-passivated beans for (V instance : passivated) { InfinispanEjbLogger.ROOT_LOGGER.tracef("Invoking post-activate callback for bean %s", instance.getId()); try { instance.postActivate(); } catch (RuntimeException | Error t) { InfinispanEjbLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } } // Abort passivation if any beans failed to pre-passivate throw e; } } catch (IOException e) { InfinispanEjbLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } } void cascadeEvict(BeanCreationMetaDataKey<K> key) { // Cascade eviction to access meta data entry this.getCache().evict(new InfinispanBeanAccessMetaDataKey<>(key.getId())); } @SuppressWarnings("unchecked") @Override public <KK, VV> Cache<KK, VV> getCache() { return (Cache<KK, VV>) this.cache.get(); } }
7,929
46.48503
203
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanGroupSerializationContextInitializer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.infinispan.protostream.SerializationContext; import org.jboss.ejb.client.SessionID; import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer; import org.wildfly.clustering.marshalling.protostream.FunctionalMarshaller; /** * {@link org.infinispan.protostream.SerializationContextInitializer} for this package. * @author Paul Ferraro */ public class InfinispanBeanGroupSerializationContextInitializer extends AbstractSerializationContextInitializer { @SuppressWarnings("unchecked") @Override public void registerMarshallers(SerializationContext context) { context.registerMarshaller(new FunctionalMarshaller<>((Class<InfinispanBeanGroupKey<SessionID>>) (Class<?>) InfinispanBeanGroupKey.class, SessionID.class, InfinispanBeanGroupKey::getId, InfinispanBeanGroupKey::new)); } }
1,929
44.952381
224
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanGroupKey.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.wildfly.clustering.ee.infinispan.GroupedKey; import org.wildfly.clustering.ejb.cache.bean.BeanGroupKey; /** * The key used to cache a group of beans. * @author Paul Ferraro * @param <K> the bean group identifier type */ public class InfinispanBeanGroupKey<K> extends GroupedKey<K> implements BeanGroupKey<K> { public InfinispanBeanGroupKey(K id) { super(id); } }
1,473
36.794872
89
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanAccessMetaDataKey.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.wildfly.clustering.ee.infinispan.GroupedKey; import org.wildfly.clustering.ejb.cache.bean.BeanAccessMetaDataKey; /** * The key used to cache the access metadata of a bean. * @author Paul Ferraro * @param <K> the bean identifier type */ public class InfinispanBeanAccessMetaDataKey<K> extends GroupedKey<K> implements BeanAccessMetaDataKey<K> { public InfinispanBeanAccessMetaDataKey(K id) { super(id); } }
1,516
37.897436
107
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanMetaDataFactoryConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.wildfly.clustering.ee.infinispan.InfinispanConfiguration; import org.wildfly.clustering.ejb.cache.bean.BeanMetaDataFactoryConfiguration; /** * Encapsulate the configuration for an {@link InfinispanBeanMetaDataFactory}. * @author Paul Ferraro */ public interface InfinispanBeanMetaDataFactoryConfiguration extends BeanMetaDataFactoryConfiguration, InfinispanConfiguration { }
1,467
42.176471
127
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/BeanGroupFilter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.infinispan.metadata.Metadata; import org.infinispan.notifications.cachelistener.filter.CacheEventFilter; import org.infinispan.notifications.cachelistener.filter.EventType; /** * Filters a cache for entries specific to a particular bean. * @author Paul Ferraro */ public enum BeanGroupFilter implements CacheEventFilter<Object, Object> { INSTANCE; @Override public boolean accept(Object key, Object oldValue, Metadata oldMetadata, Object newValue, Metadata newMetadata, EventType eventType) { return key instanceof InfinispanBeanGroupKey; } }
1,660
39.512195
138
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanGroupManagerServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import org.infinispan.Cache; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.ee.Creator; import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.Remover; import org.wildfly.clustering.ee.cache.CacheProperties; import org.wildfly.clustering.ee.infinispan.InfinispanConfiguration; import org.wildfly.clustering.ejb.DeploymentConfiguration; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.cache.bean.BeanGroupManager; import org.wildfly.clustering.ejb.cache.bean.BeanGroupManagerServiceNameProvider; import org.wildfly.clustering.ejb.cache.bean.DefaultBeanGroupManager; import org.wildfly.clustering.ejb.cache.bean.DefaultBeanGroupManagerConfiguration; import org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValueFactory; import org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller; import org.wildfly.clustering.marshalling.spi.MarshalledValue; import org.wildfly.clustering.marshalling.spi.MarshalledValueFactory; import org.wildfly.clustering.service.CompositeDependency; import org.wildfly.clustering.service.FunctionalService; import org.wildfly.clustering.service.SupplierDependency; /** * Configures a service that provides a {@link BeanGroupManager} for a bean deployment. * @author Paul Ferraro * @param <K> the bean identifier type * @param <V> the bean instance type */ public class InfinispanBeanGroupManagerServiceConfigurator<K, V extends BeanInstance<K>> extends BeanGroupManagerServiceNameProvider implements CapabilityServiceConfigurator, Supplier<BeanGroupManager<K, V>>, InfinispanConfiguration { private final SupplierDependency<Cache<?, ?>> cache; private final SupplierDependency<ByteBufferMarshaller> marshaller; public InfinispanBeanGroupManagerServiceConfigurator(DeploymentConfiguration config, SupplierDependency<Cache<?, ?>> cache, SupplierDependency<ByteBufferMarshaller> marshaller) { super(config); this.cache = cache; this.marshaller = marshaller; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceName name = this.getServiceName(); ServiceBuilder<?> builder = target.addService(name); Consumer<BeanGroupManager<K, V>> manager = new CompositeDependency(this.marshaller, this.cache).register(builder).provides(name); return builder.setInstance(new FunctionalService<>(manager, Function.identity(), this)); } @Override public BeanGroupManager<K, V> get() { CacheProperties properties = this.getCacheProperties(); InfinispanBeanGroupManager<K, V, ByteBufferMarshaller> factory = new InfinispanBeanGroupManager<>(this); MarshalledValueFactory<ByteBufferMarshaller> marshalledValueFactory = new ByteBufferMarshalledValueFactory(this.marshaller.get()); return new DefaultBeanGroupManager<>(new DefaultBeanGroupManagerConfiguration<K, V, ByteBufferMarshaller>() { @Override public Creator<K, MarshalledValue<Map<K, V>, ByteBufferMarshaller>, MarshalledValue<Map<K, V>, ByteBufferMarshaller>> getCreator() { return factory; } @Override public Remover<K> getRemover() { return factory; } @Override public MutatorFactory<K, MarshalledValue<Map<K, V>, ByteBufferMarshaller>> getMutatorFactory() { return factory; } @Override public CacheProperties getCacheProperties() { return properties; } @Override public MarshalledValueFactory<ByteBufferMarshaller> getMarshalledValueFactory() { return marshalledValueFactory; } }); } @SuppressWarnings("unchecked") @Override public <KK, VV> Cache<KK, VV> getCache() { return (Cache<KK, VV>) this.cache.get(); } }
5,306
43.974576
234
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanManager.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.time.Duration; import java.util.EnumSet; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeoutException; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.UnaryOperator; import java.util.stream.Stream; import org.infinispan.Cache; import org.infinispan.commons.CacheException; import org.infinispan.configuration.cache.CacheMode; import org.infinispan.context.Flag; import org.jboss.ejb.client.Affinity; import org.jboss.ejb.client.ClusterAffinity; import org.jboss.ejb.client.NodeAffinity; import org.wildfly.clustering.ee.Batcher; import org.wildfly.clustering.ee.Key; import org.wildfly.clustering.ee.Scheduler; import org.wildfly.clustering.ee.cache.CacheProperties; import org.wildfly.clustering.ee.cache.IdentifierFactory; import org.wildfly.clustering.ee.cache.tx.TransactionBatch; import org.wildfly.clustering.ee.expiration.ExpirationMetaData; import org.wildfly.clustering.ee.infinispan.GroupedKey; import org.wildfly.clustering.ee.infinispan.PrimaryOwnerLocator; import org.wildfly.clustering.ee.infinispan.affinity.AffinityIdentifierFactory; import org.wildfly.clustering.ee.infinispan.scheduler.PrimaryOwnerScheduler; import org.wildfly.clustering.ee.infinispan.scheduler.ScheduleLocalEntriesTask; import org.wildfly.clustering.ee.infinispan.scheduler.ScheduleWithMetaDataCommand; import org.wildfly.clustering.ee.infinispan.scheduler.ScheduleWithTransientMetaDataCommand; import org.wildfly.clustering.ee.infinispan.scheduler.CacheEntryScheduler; import org.wildfly.clustering.ee.infinispan.scheduler.SchedulerTopologyChangeListener; import org.wildfly.clustering.ee.infinispan.tx.InfinispanBatcher; import org.wildfly.clustering.ejb.bean.Bean; import org.wildfly.clustering.ejb.bean.BeanExpirationConfiguration; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.bean.BeanManager; import org.wildfly.clustering.ejb.cache.bean.BeanFactory; import org.wildfly.clustering.ejb.cache.bean.MutableBean; import org.wildfly.clustering.ejb.cache.bean.OnCloseBean; import org.wildfly.clustering.ejb.infinispan.logging.InfinispanEjbLogger; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.infinispan.distribution.CacheLocality; import org.wildfly.clustering.infinispan.distribution.Locality; import org.wildfly.clustering.infinispan.distribution.SimpleLocality; import org.wildfly.clustering.infinispan.listener.ListenerRegistration; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; /** * A {@link BeanManager} implementation backed by an infinispan cache. * @author Paul Ferraro * @param <K> the bean identifier type * @param <V> the bean instance type * @param <M> the bean metadata value type */ public class InfinispanBeanManager<K, V extends BeanInstance<K>, M> implements BeanManager<K, V, TransactionBatch> { private final Cache<Key<K>, Object> cache; private final CacheProperties properties; private final BeanFactory<K, V, M> beanFactory; private final IdentifierFactory<K> identifierFactory; private final CommandDispatcherFactory dispatcherFactory; private final BeanExpirationConfiguration<K, V> expiration; private final Batcher<TransactionBatch> batcher; private final Predicate<Map.Entry<? super Key<K>, ? super Object>> filter; private final Function<Key<K>, Node> primaryOwnerLocator; private final Affinity strongAffinity; private volatile Scheduler<K, ExpirationMetaData> scheduler; private volatile ListenerRegistration schedulerListenerRegistration; private volatile UnaryOperator<Bean<K, V>> transformer; public InfinispanBeanManager(InfinispanBeanManagerConfiguration<K, V, M> configuration) { this.beanFactory = configuration.getBeanFactory(); this.cache = configuration.getCache(); this.properties = configuration.getCacheProperties(); this.batcher = new InfinispanBatcher(this.cache); this.identifierFactory = new AffinityIdentifierFactory<>(configuration.getIdentifierFactory(), this.cache, configuration.getAffinityFactory()); this.dispatcherFactory = configuration.getCommandDispatcherFactory(); this.expiration = configuration.getExpiration(); this.primaryOwnerLocator = new PrimaryOwnerLocator<>(configuration.getCache(), configuration.getGroup()); Group group = configuration.getGroup(); this.strongAffinity = this.cache.getCacheConfiguration().clustering().cacheMode().isClustered() ? new ClusterAffinity(group.getName()) : new NodeAffinity(group.getLocalMember().getName()); this.filter = new InfinispanBeanCreationMetaDataFilter<>(configuration.getBeanName()); } @Override public void start() { this.identifierFactory.start(); Duration stopTimeout = Duration.ofMillis(this.cache.getCacheConfiguration().transaction().cacheStopTimeout()); CacheEntryScheduler<K, ExpirationMetaData> localScheduler = (this.expiration != null) && !this.expiration.getTimeout().isZero() ? new BeanExpirationScheduler<>(this.dispatcherFactory.getGroup(), this.batcher, this.beanFactory, this.expiration, stopTimeout) : null; String dispatcherName = String.join("/", this.cache.getName(), this.filter.toString()); this.scheduler = (localScheduler != null) ? (this.dispatcherFactory.getGroup().isSingleton() ? localScheduler : new PrimaryOwnerScheduler<>(this.dispatcherFactory, dispatcherName, localScheduler, this.primaryOwnerLocator, InfinispanBeanCreationMetaDataKey::new, this.properties.isTransactional() ? ScheduleWithMetaDataCommand::new : ScheduleWithTransientMetaDataCommand::new)) : null; BiConsumer<Locality, Locality> scheduleTask = (localScheduler != null) ? new ScheduleLocalEntriesTask<>(this.cache, this.filter, localScheduler) : null; this.schedulerListenerRegistration = (localScheduler != null) ? new SchedulerTopologyChangeListener<>(this.cache, localScheduler, scheduleTask).register() : null; if (scheduleTask != null) { // Schedule expiration of existing beans that we own scheduleTask.accept(new SimpleLocality(false), new CacheLocality(this.cache)); } // If bean has expiration configuration, perform expiration task on close Consumer<Bean<K, V>> closeTask = (this.expiration != null) ? bean -> { if (bean.isValid()) { if (this.scheduler != null) { // Schedule expiration of bean this.scheduler.schedule(bean.getId(), bean.getMetaData()); } else { // If timeout = 0, remove immediately bean.remove(this.expiration.getExpirationListener()); } } } : null; this.transformer = (closeTask != null) ? bean -> new OnCloseBean<>(bean, closeTask) : UnaryOperator.identity(); } @Override public void stop() { if (this.schedulerListenerRegistration != null) { this.schedulerListenerRegistration.close(); } if (this.scheduler != null) { this.scheduler.close(); } this.identifierFactory.stop(); } @Override public boolean isRemotable(final Throwable throwable) { Throwable subject = throwable; while (subject != null) { if (subject instanceof CacheException) { return false; } subject = subject.getCause(); } return true; } @Override public Affinity getStrongAffinity() { return this.strongAffinity; } @Override public Affinity getWeakAffinity(K id) { org.infinispan.configuration.cache.Configuration config = this.cache.getCacheConfiguration(); CacheMode mode = config.clustering().cacheMode(); if (mode.isClustered()) { Node member = this.primaryOwnerLocator.apply(new GroupedKey<>(id)); return new NodeAffinity(member.getName()); } return Affinity.NONE; } @Override public Bean<K, V> createBean(V instance, K groupId) { K id = instance.getId(); InfinispanEjbLogger.ROOT_LOGGER.tracef("Creating bean %s associated with group %s", id, groupId); MutableBean<K, V> bean = this.beanFactory.createBean(id, this.beanFactory.createValue(instance, groupId)); bean.setInstance(instance); return bean; } @Override public Bean<K, V> findBean(K id) throws TimeoutException { InfinispanEjbLogger.ROOT_LOGGER.tracef("Locating bean %s", id); M value = this.beanFactory.findValue(id); if (value == null) { InfinispanEjbLogger.ROOT_LOGGER.debugf("Could not find bean %s", id); return null; } if (this.scheduler != null) { this.scheduler.cancel(id); } try { @SuppressWarnings("resource") Bean<K, V> bean = this.beanFactory.createBean(id, value); if (bean.getInstance() == null) { InfinispanEjbLogger.ROOT_LOGGER.tracef("Bean %s metadata was found, but bean instance was not, most likely due to passivation failure.", id); try { this.beanFactory.purge(id); } finally { bean.close(); } return null; } if (bean.getMetaData().isExpired()) { InfinispanEjbLogger.ROOT_LOGGER.debugf("Bean %s found, but was expired", id); try { bean.remove(this.expiration.getExpirationListener()); } finally { bean.close(); } return null; } return this.transformer.apply(bean); } catch (org.infinispan.util.concurrent.TimeoutException e) { throw new TimeoutException(e.getLocalizedMessage()); } } @Override public Supplier<K> getIdentifierFactory() { return this.identifierFactory; } @Override public Batcher<TransactionBatch> getBatcher() { return this.batcher; } @Override public int getActiveCount() { return this.count(EnumSet.of(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_LOAD)); } @Override public int getPassiveCount() { return this.count(EnumSet.of(Flag.CACHE_MODE_LOCAL)) - this.getActiveCount(); } private int count(Set<Flag> flags) { try (Stream<Key<K>> keys = this.cache.getAdvancedCache().withFlags(flags).keySet().stream()) { return (int) keys.filter(InfinispanBeanGroupKey.class::isInstance).count(); } } }
11,966
45.383721
392
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanManagementConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import org.wildfly.clustering.ee.infinispan.InfinispanCacheConfiguration; import org.wildfly.clustering.ejb.bean.BeanManagementConfiguration; /** * Configuration of an Infinispan-based bean management provider. * @author Paul Ferraro */ public interface InfinispanBeanManagementConfiguration extends InfinispanCacheConfiguration, BeanManagementConfiguration { }
1,443
41.470588
122
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanGroupManager.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.util.Map; import org.infinispan.Cache; import org.wildfly.clustering.ee.Creator; import org.wildfly.clustering.ee.Mutator; import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.Remover; import org.wildfly.clustering.ee.infinispan.InfinispanConfiguration; import org.wildfly.clustering.ee.infinispan.InfinispanMutatorFactory; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.cache.bean.BeanGroupKey; import org.wildfly.clustering.marshalling.spi.MarshalledValue; /** * Manages the cache entry for a bean group. * @author Paul Ferraro * @param <K> the bean identifier type * @param <V> the bean instance type * @param <C> the marshalled value context type */ public class InfinispanBeanGroupManager<K, V extends BeanInstance<K>, C> implements Creator<K, MarshalledValue<Map<K, V>, C>, MarshalledValue<Map<K, V>, C>>, Remover<K>, MutatorFactory<K, MarshalledValue<Map<K, V>, C>> { private final Cache<BeanGroupKey<K>, MarshalledValue<Map<K, V>, C>> cache; private final Cache<BeanGroupKey<K>, MarshalledValue<Map<K, V>, C>> removeCache; private final MutatorFactory<BeanGroupKey<K>, MarshalledValue<Map<K, V>, C>> mutatorFactory; public InfinispanBeanGroupManager(InfinispanConfiguration configuration) { this.cache = configuration.getCache(); this.removeCache = configuration.getWriteOnlyCache(); this.mutatorFactory = new InfinispanMutatorFactory<>(configuration.getCache()); } @Override public MarshalledValue<Map<K, V>, C> createValue(K id, MarshalledValue<Map<K, V>, C> defaultValue) { MarshalledValue<Map<K, V>, C> value = this.cache.putIfAbsent(new InfinispanBeanGroupKey<>(id), defaultValue); return (value != null) ? value : defaultValue; } @Override public boolean remove(K id) { this.removeCache.remove(new InfinispanBeanGroupKey<>(id)); return true; } @Override public Mutator createMutator(K id, MarshalledValue<Map<K, V>, C> value) { return this.mutatorFactory.createMutator(new InfinispanBeanGroupKey<>(id), value); } }
3,220
42.527027
220
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/SessionIDKeySerializer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.util.function.Function; import org.jboss.ejb.client.SessionID; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.ee.Key; import org.wildfly.clustering.ejb.client.SessionIDSerializer; import org.wildfly.clustering.marshalling.spi.BinaryFormatter; import org.wildfly.clustering.marshalling.spi.Formatter; import org.wildfly.clustering.marshalling.spi.Serializer; /** * {@link Serializer} for a {@link SessionID} based {@link Key}. * @author Paul Ferraro * @param <K> the key type */ public class SessionIDKeySerializer<K extends Key<SessionID>> implements Serializer<K> { private final Function<SessionID, K> factory; SessionIDKeySerializer(Function<SessionID, K> factory) { this.factory = factory; } @Override public void write(DataOutput output, K key) throws IOException { SessionIDSerializer.INSTANCE.write(output, key.getId()); } @Override public K read(DataInput input) throws IOException { return this.factory.apply(SessionIDSerializer.INSTANCE.read(input)); } @MetaInfServices(Formatter.class) public static class InfinispanBeanCreationMetaDataKeyFormatter extends BinaryFormatter<InfinispanBeanCreationMetaDataKey<SessionID>> { @SuppressWarnings("unchecked") public InfinispanBeanCreationMetaDataKeyFormatter() { super((Class<InfinispanBeanCreationMetaDataKey<SessionID>>) (Class<?>) InfinispanBeanCreationMetaDataKey.class, new SessionIDKeySerializer<>(InfinispanBeanCreationMetaDataKey::new)); } } @MetaInfServices(Formatter.class) public static class InfinispanBeanAccessMetaDataKeyFormatter extends BinaryFormatter<InfinispanBeanAccessMetaDataKey<SessionID>> { @SuppressWarnings("unchecked") public InfinispanBeanAccessMetaDataKeyFormatter() { super((Class<InfinispanBeanAccessMetaDataKey<SessionID>>) (Class<?>) InfinispanBeanAccessMetaDataKey.class, new SessionIDKeySerializer<>(InfinispanBeanAccessMetaDataKey::new)); } } @MetaInfServices(Formatter.class) public static class InfinispanBeanGroupKeyFormatter extends BinaryFormatter<InfinispanBeanGroupKey<SessionID>> { @SuppressWarnings("unchecked") public InfinispanBeanGroupKeyFormatter() { super((Class<InfinispanBeanGroupKey<SessionID>>) (Class<?>) InfinispanBeanGroupKey.class, new SessionIDKeySerializer<>(InfinispanBeanGroupKey::new)); } } }
3,616
41.552941
194
java
null
wildfly-main/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanCreationMetaDataFilter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.ejb.infinispan.bean; import java.util.Map; import org.infinispan.util.function.SerializablePredicate; import org.wildfly.clustering.ee.Key; import org.wildfly.clustering.ejb.cache.bean.BeanCreationMetaData; /** * Filters a cache for entries specific to a particular bean. * @author Paul Ferraro * @param <K> the bean identifier type */ public class InfinispanBeanCreationMetaDataFilter<K> implements SerializablePredicate<Map.Entry<? super Key<K>, ? super Object>> { private static final long serialVersionUID = -1079989480899595045L; private final String beanName; public InfinispanBeanCreationMetaDataFilter(String beanName) { this.beanName = beanName; } @Override public boolean test(Map.Entry<? super Key<K>, ? super Object> entry) { if (entry.getKey() instanceof InfinispanBeanCreationMetaDataKey) { Object value = entry.getValue(); if (value instanceof BeanCreationMetaData) { @SuppressWarnings("unchecked") BeanCreationMetaData<K> metaData = (BeanCreationMetaData<K>) value; return this.beanName.equals(metaData.getName()); } } return false; } @Override public String toString() { return this.beanName; } }
2,344
36.222222
130
java
null
wildfly-main/clustering/context/src/test/java/org/wildfly/clustering/context/ContextualExecutorServiceTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Test; import org.mockito.ArgumentCaptor; /** * @author Paul Ferraro */ public class ContextualExecutorServiceTestCase { private final ExecutorService executor = mock(ExecutorService.class); private final Contextualizer contextualizer = mock(Contextualizer.class); private final ExecutorService subject = new ContextualExecutorService(this.executor, this.contextualizer); @After public void after() { reset(this.executor, this.contextualizer); } @Test public void execute() { Runnable command = mock(Runnable.class); Runnable contextualCommand = mock(Runnable.class); when(this.contextualizer.contextualize(same(command))).thenReturn(contextualCommand); this.subject.execute(command); verify(this.executor).execute(contextualCommand); } @Test public void shutdown() { this.subject.shutdown(); verify(this.executor).shutdown(); } @Test public void shutdownNow() { List<Runnable> expected = Collections.singletonList(mock(Runnable.class)); when(this.executor.shutdownNow()).thenReturn(expected); List<Runnable> result = this.subject.shutdownNow(); assertSame(expected, result); } @Test public void isShutdown() { when(this.executor.isShutdown()).thenReturn(false, true); assertFalse(this.subject.isShutdown()); assertTrue(this.subject.isShutdown()); } @Test public void isTerminated() { when(this.executor.isTerminated()).thenReturn(false, true); assertFalse(this.subject.isTerminated()); assertTrue(this.subject.isTerminated()); } @Test public void awaitTermination() throws InterruptedException { when(this.executor.awaitTermination(10L, TimeUnit.MINUTES)).thenReturn(false, true); assertFalse(this.subject.awaitTermination(10L, TimeUnit.MINUTES)); assertTrue(this.subject.awaitTermination(10L, TimeUnit.MINUTES)); } @Test public void submitCallable() { Callable<Object> task = mock(Callable.class); Callable<Object> contextualTask = mock(Callable.class); Future<Object> expected = mock(Future.class); when(this.contextualizer.contextualize(task)).thenReturn(contextualTask); when(this.executor.submit(same(contextualTask))).thenReturn(expected); Future<Object> result = this.subject.submit(task); assertSame(expected, result); } @Test public void submitRunnableWithResult() { Runnable task = mock(Runnable.class); Runnable contextualTask = mock(Runnable.class); Future<Object> expected = mock(Future.class); Object param = new Object(); when(this.contextualizer.contextualize(task)).thenReturn(contextualTask); when(this.executor.submit(same(contextualTask), same(param))).thenReturn(expected); Future<Object> result = this.subject.submit(task, param); assertSame(expected, result); } @SuppressWarnings("unchecked") @Test public void submit() { Runnable task = mock(Runnable.class); Runnable contextualTask = mock(Runnable.class); @SuppressWarnings("rawtypes") Future expected = mock(Future.class); when(this.contextualizer.contextualize(task)).thenReturn(contextualTask); when(this.executor.submit(same(contextualTask))).thenReturn(expected); Future<?> result = this.subject.submit(task); assertSame(expected, result); } @Test public void invokeAll() throws InterruptedException { Callable<Object> task1 = mock(Callable.class); Callable<Object> task2 = mock(Callable.class); Callable<Object> task3 = mock(Callable.class); Callable<Object> contextualTask1 = mock(Callable.class); Callable<Object> contextualTask2 = mock(Callable.class); Callable<Object> contextualTask3 = mock(Callable.class); @SuppressWarnings("unchecked") ArgumentCaptor<List<Callable<Object>>> capturedTasks = ArgumentCaptor.forClass(List.class); @SuppressWarnings("unchecked") List<Future<Object>> expected = Collections.singletonList(mock(Future.class)); when(this.contextualizer.contextualize(task1)).thenReturn(contextualTask1); when(this.contextualizer.contextualize(task2)).thenReturn(contextualTask2); when(this.contextualizer.contextualize(task3)).thenReturn(contextualTask3); when(this.executor.invokeAll(capturedTasks.capture())).thenReturn(expected); List<Future<Object>> result = this.subject.invokeAll(Arrays.asList(task1, task2, task3)); assertSame(expected, result); List<Callable<Object>> tasks = capturedTasks.getValue(); assertEquals(3, tasks.size()); assertSame(contextualTask1, tasks.get(0)); assertSame(contextualTask2, tasks.get(1)); assertSame(contextualTask3, tasks.get(2)); } @Test public void invokeAllWithTimeout() throws InterruptedException { Callable<Object> task1 = mock(Callable.class); Callable<Object> task2 = mock(Callable.class); Callable<Object> task3 = mock(Callable.class); Callable<Object> contextualTask1 = mock(Callable.class); Callable<Object> contextualTask2 = mock(Callable.class); Callable<Object> contextualTask3 = mock(Callable.class); @SuppressWarnings("unchecked") ArgumentCaptor<List<Callable<Object>>> capturedTasks = ArgumentCaptor.forClass(List.class); @SuppressWarnings("unchecked") List<Future<Object>> expected = Collections.singletonList(mock(Future.class)); when(this.contextualizer.contextualize(task1)).thenReturn(contextualTask1); when(this.contextualizer.contextualize(task2)).thenReturn(contextualTask2); when(this.contextualizer.contextualize(task3)).thenReturn(contextualTask3); when(this.executor.invokeAll(capturedTasks.capture(), eq(10L), same(TimeUnit.MINUTES))).thenReturn(expected); List<Future<Object>> result = this.subject.invokeAll(Arrays.asList(task1, task2, task3), 10L, TimeUnit.MINUTES); assertSame(expected, result); List<Callable<Object>> tasks = capturedTasks.getValue(); assertEquals(3, tasks.size()); assertSame(contextualTask1, tasks.get(0)); assertSame(contextualTask2, tasks.get(1)); assertSame(contextualTask3, tasks.get(2)); } @Test public void invokeAny() throws InterruptedException, ExecutionException { Callable<Object> task1 = mock(Callable.class); Callable<Object> task2 = mock(Callable.class); Callable<Object> task3 = mock(Callable.class); Callable<Object> contextualTask1 = mock(Callable.class); Callable<Object> contextualTask2 = mock(Callable.class); Callable<Object> contextualTask3 = mock(Callable.class); @SuppressWarnings("unchecked") ArgumentCaptor<List<Callable<Object>>> capturedTasks = ArgumentCaptor.forClass(List.class); Object expected = new Object(); when(this.contextualizer.contextualize(task1)).thenReturn(contextualTask1); when(this.contextualizer.contextualize(task2)).thenReturn(contextualTask2); when(this.contextualizer.contextualize(task3)).thenReturn(contextualTask3); when(this.executor.invokeAny(capturedTasks.capture())).thenReturn(expected); Object result = this.subject.invokeAny(Arrays.asList(task1, task2, task3)); assertSame(expected, result); List<Callable<Object>> tasks = capturedTasks.getValue(); assertEquals(3, tasks.size()); assertSame(contextualTask1, tasks.get(0)); assertSame(contextualTask2, tasks.get(1)); assertSame(contextualTask3, tasks.get(2)); } @Test public void invokeAnyWithTimeout() throws InterruptedException, ExecutionException, TimeoutException { Callable<Object> task1 = mock(Callable.class); Callable<Object> task2 = mock(Callable.class); Callable<Object> task3 = mock(Callable.class); Callable<Object> contextualTask1 = mock(Callable.class); Callable<Object> contextualTask2 = mock(Callable.class); Callable<Object> contextualTask3 = mock(Callable.class); @SuppressWarnings("unchecked") ArgumentCaptor<List<Callable<Object>>> capturedTasks = ArgumentCaptor.forClass(List.class); Object expected = new Object(); when(this.contextualizer.contextualize(task1)).thenReturn(contextualTask1); when(this.contextualizer.contextualize(task2)).thenReturn(contextualTask2); when(this.contextualizer.contextualize(task3)).thenReturn(contextualTask3); when(this.executor.invokeAny(capturedTasks.capture(), eq(10L), same(TimeUnit.MINUTES))).thenReturn(expected); Object result = this.subject.invokeAny(Arrays.asList(task1, task2, task3), 10L, TimeUnit.MINUTES); assertSame(expected, result); List<Callable<Object>> tasks = capturedTasks.getValue(); assertEquals(3, tasks.size()); assertSame(contextualTask1, tasks.get(0)); assertSame(contextualTask2, tasks.get(1)); assertSame(contextualTask3, tasks.get(2)); } }
10,781
39.081784
120
java
null
wildfly-main/clustering/context/src/test/java/org/wildfly/clustering/context/CompositeContextualizerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import java.util.concurrent.Callable; import java.util.function.Supplier; import org.junit.Test; import org.wildfly.common.function.ExceptionRunnable; import org.wildfly.common.function.ExceptionSupplier; /** * @author Paul Ferraro */ public class CompositeContextualizerTestCase { @Test public void test() { Contextualizer contextualizer1 = mock(Contextualizer.class); Contextualizer contextualizer2 = mock(Contextualizer.class); Contextualizer contextualizer3 = mock(Contextualizer.class); Contextualizer contextualizer = new CompositeContextualizer(contextualizer1, contextualizer2, contextualizer3); Runnable runner = mock(Runnable.class); Runnable contextualRunner1 = mock(Runnable.class); Runnable contextualRunner2 = mock(Runnable.class); Runnable contextualRunner3 = mock(Runnable.class); when(contextualizer1.contextualize(runner)).thenReturn(contextualRunner1); when(contextualizer2.contextualize(contextualRunner1)).thenReturn(contextualRunner2); when(contextualizer3.contextualize(contextualRunner2)).thenReturn(contextualRunner3); assertSame(contextualRunner3, contextualizer.contextualize(runner)); ExceptionRunnable<Exception> exceptionRunner = mock(ExceptionRunnable.class); ExceptionRunnable<Exception> contextualExceptionRunner1 = mock(ExceptionRunnable.class); ExceptionRunnable<Exception> contextualExceptionRunner2 = mock(ExceptionRunnable.class); ExceptionRunnable<Exception> contextualExceptionRunner3 = mock(ExceptionRunnable.class); when(contextualizer1.contextualize(exceptionRunner)).thenReturn(contextualExceptionRunner1); when(contextualizer2.contextualize(contextualExceptionRunner1)).thenReturn(contextualExceptionRunner2); when(contextualizer3.contextualize(contextualExceptionRunner2)).thenReturn(contextualExceptionRunner3); assertSame(contextualExceptionRunner3, contextualizer.contextualize(exceptionRunner)); Callable<Object> caller = mock(Callable.class); Callable<Object> contextualCaller1 = mock(Callable.class); Callable<Object> contextualCaller2 = mock(Callable.class); Callable<Object> contextualCaller3 = mock(Callable.class); when(contextualizer1.contextualize(caller)).thenReturn(contextualCaller1); when(contextualizer2.contextualize(contextualCaller1)).thenReturn(contextualCaller2); when(contextualizer3.contextualize(contextualCaller2)).thenReturn(contextualCaller3); assertSame(contextualCaller3, contextualizer.contextualize(caller)); Supplier<Object> supplier = mock(Supplier.class); Supplier<Object> contextualSupplier1 = mock(Supplier.class); Supplier<Object> contextualSupplier2 = mock(Supplier.class); Supplier<Object> contextualSupplier3 = mock(Supplier.class); when(contextualizer1.contextualize(supplier)).thenReturn(contextualSupplier1); when(contextualizer2.contextualize(contextualSupplier1)).thenReturn(contextualSupplier2); when(contextualizer3.contextualize(contextualSupplier2)).thenReturn(contextualSupplier3); assertSame(contextualSupplier3, contextualizer.contextualize(supplier)); ExceptionSupplier<Object, Exception> exceptionSupplier = mock(ExceptionSupplier.class); ExceptionSupplier<Object, Exception> contextualExceptionSupplier1 = mock(ExceptionSupplier.class); ExceptionSupplier<Object, Exception> contextualExceptionSupplier2 = mock(ExceptionSupplier.class); ExceptionSupplier<Object, Exception> contextualExceptionSupplier3 = mock(ExceptionSupplier.class); when(contextualizer1.contextualize(exceptionSupplier)).thenReturn(contextualExceptionSupplier1); when(contextualizer2.contextualize(contextualExceptionSupplier1)).thenReturn(contextualExceptionSupplier2); when(contextualizer3.contextualize(contextualExceptionSupplier2)).thenReturn(contextualExceptionSupplier3); assertSame(contextualExceptionSupplier3, contextualizer.contextualize(exceptionSupplier)); } }
5,266
50.135922
119
java
null
wildfly-main/clustering/context/src/test/java/org/wildfly/clustering/context/ContextualThreadFactoryTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import java.util.concurrent.ThreadFactory; import org.junit.Test; /** * @author Paul Ferraro */ public class ContextualThreadFactoryTestCase { @Test public void test() { ThreadFactory factory = mock(ThreadFactory.class); Object targetContext = new Object(); ThreadContextReference<Object> reference = mock(ThreadContextReference.class); Contextualizer contextualizer = mock(Contextualizer.class); ThreadFactory subject = new ContextualThreadFactory<>(factory, targetContext, reference, contextualizer); Runnable task = mock(Runnable.class); Runnable contextualTask = mock(Runnable.class); Thread expected = new Thread(); when(contextualizer.contextualize(task)).thenReturn(contextualTask); when(factory.newThread(same(contextualTask))).thenReturn(expected); Thread result = subject.newThread(task); assertSame(expected, result); verify(reference).accept(same(expected), same(targetContext)); } }
2,158
36.224138
113
java
null
wildfly-main/clustering/context/src/test/java/org/wildfly/clustering/context/ContextReferenceExecutorTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import static org.junit.Assert.*; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import org.junit.Test; import org.wildfly.common.function.ExceptionRunnable; import org.wildfly.common.function.ExceptionSupplier; /** * Unit test for {@link ContextReferenceExecutor}. * @author Paul Ferraro */ public class ContextReferenceExecutorTestCase { @Test public void test() throws Exception { Object original = new Object(); Object target = new Object(); Object result = new Object(); AtomicReference<Object> resultRef = new AtomicReference<>(); ContextReference<Object> contextRef = new AtomicContextReference<>(original); Contextualizer contextualizer = new ContextReferenceExecutor<>(target, contextRef); Runnable runner = new Runnable() { @Override public void run() { assertSame(target, contextRef.get()); resultRef.set(result); } }; assertSame(original, contextRef.get()); contextualizer.contextualize(runner).run(); assertSame(original, contextRef.get()); assertSame(result, resultRef.get()); resultRef.set(null); ExceptionRunnable<Exception> exceptionRunner = new ExceptionRunnable<>() { @Override public void run() throws Exception { assertSame(target, contextRef.get()); resultRef.set(result); } }; assertSame(original, contextRef.get()); contextualizer.contextualize(exceptionRunner).run(); assertSame(original, contextRef.get()); assertSame(result, resultRef.get()); resultRef.set(null); Callable<Object> caller = new Callable<>() { @Override public Object call() { assertSame(target, contextRef.get()); return result; } }; assertSame(original, contextRef.get()); assertSame(result, contextualizer.contextualize(caller).call()); assertSame(original, contextRef.get()); Supplier<Object> supplier = new Supplier<>() { @Override public Object get() { assertSame(target, contextRef.get()); return result; } }; assertSame(original, contextRef.get()); assertSame(result, contextualizer.contextualize(supplier).get()); assertSame(original, contextRef.get()); ExceptionSupplier<Object, Exception> exceptionSupplier = new ExceptionSupplier<>() { @Override public Object get() { assertSame(target, contextRef.get()); return result; } }; assertSame(original, contextRef.get()); assertSame(result, contextualizer.contextualize(exceptionSupplier).get()); assertSame(original, contextRef.get()); } static class AtomicContextReference<T> implements ContextReference<T> { private AtomicReference<T> ref; AtomicContextReference(T initial) { this.ref = new AtomicReference<>(initial); } @Override public void accept(T value) { this.ref.set(value); } @Override public T get() { return this.ref.get(); } } }
4,506
32.385185
92
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ContextReference.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.function.Consumer; import java.util.function.Supplier; /** * Reference to some context. * @author Paul Ferraro */ public interface ContextReference<C> extends Supplier<C>, Consumer<C> { }
1,274
36.5
71
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ThreadContextReference.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.function.BiConsumer; import java.util.function.Function; /** * Reference that can be associated with an arbitrary thread. * @author Paul Ferraro */ public interface ThreadContextReference<C> extends ContextReference<C>, Function<Thread, C>, BiConsumer<Thread, C> { @Override default void accept(C context) { this.accept(Thread.currentThread(), context); } @Override default C get() { return this.apply(Thread.currentThread()); } }
1,559
34.454545
116
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ContextClassLoaderReference.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.AbstractMap; import java.util.Map; import org.wildfly.security.ParametricPrivilegedAction; import org.wildfly.security.manager.WildFlySecurityManager; /** * Thread-aware reference for a context {@link ClassLoader}. * @author Paul Ferraro */ public enum ContextClassLoaderReference implements ThreadContextReference<ClassLoader> { INSTANCE; private static final ParametricPrivilegedAction<ClassLoader, Thread> GET_CONTEXT_CLASS_LOADER_ACTION = new ParametricPrivilegedAction<>() { @Override public ClassLoader run(Thread thread) { return thread.getContextClassLoader(); } }; private static final ParametricPrivilegedAction<Void, Map.Entry<Thread, ClassLoader>> SET_CONTEXT_CLASS_LOADER_ACTION = new ParametricPrivilegedAction<>() { @Override public Void run(Map.Entry<Thread, ClassLoader> entry) { entry.getKey().setContextClassLoader(entry.getValue()); return null; } }; @Override public ClassLoader apply(Thread thread) { return WildFlySecurityManager.doUnchecked(thread, GET_CONTEXT_CLASS_LOADER_ACTION); } @Override public void accept(Thread thread, ClassLoader loader) { WildFlySecurityManager.doUnchecked(new AbstractMap.SimpleImmutableEntry<>(thread, loader), SET_CONTEXT_CLASS_LOADER_ACTION); } }
2,439
37.730159
160
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ContextualExecutor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.concurrent.Callable; import java.util.concurrent.Executor; import java.util.function.Supplier; import org.wildfly.common.function.ExceptionRunnable; import org.wildfly.common.function.ExceptionSupplier; /** * Facility for contextual execution. * @author Paul Ferraro */ public interface ContextualExecutor extends Contextualizer, Executor { /** * Executes the specified runner. * @param <E> the exception type * @param runner a runnable task * @throws E if execution fails */ <E extends Exception> void execute(ExceptionRunnable<E> runner) throws E; /** * Executes the specified caller with a given context. * @param <T> the return type * @param caller a callable task * @return the result of the caller * @throws Exception if execution fails */ <T> T execute(Callable<T> caller) throws Exception; /** * Executes the specified supplier with a given context. * @param <T> the return type * @param supplier a supplier task * @return the result of the supplier */ <T> T execute(Supplier<T> supplier); /** * Executes the specified supplier with a given context. * @param <T> the return type * @param <E> the exception type * @param supplier a supplier task * @return the result of the supplier * @throws E if execution fails */ <T, E extends Exception> T execute(ExceptionSupplier<T, E> supplier) throws E; @Override default Runnable contextualize(Runnable runner) { return new Runnable() { @Override public void run() { ContextualExecutor.this.execute(runner); } }; } @Override default <E extends Exception> ExceptionRunnable<E> contextualize(ExceptionRunnable<E> runner) { return new ExceptionRunnable<>() { @Override public void run() throws E { ContextualExecutor.this.execute(runner); } }; } @Override default <T> Callable<T> contextualize(Callable<T> caller) { return new Callable<>() { @Override public T call() throws Exception { return ContextualExecutor.this.execute(caller); } }; } @Override default <T> Supplier<T> contextualize(Supplier<T> supplier) { return new Supplier<>() { @Override public T get() { return ContextualExecutor.this.execute(supplier); } }; } @Override default <T, E extends Exception> ExceptionSupplier<T, E> contextualize(ExceptionSupplier<T, E> supplier) { return new ExceptionSupplier<>() { @Override public T get() throws E { return ContextualExecutor.this.execute(supplier); } }; } }
3,961
31.211382
110
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ContextReferenceExecutor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.concurrent.Callable; import java.util.function.Supplier; import org.wildfly.common.function.ExceptionRunnable; import org.wildfly.common.function.ExceptionSupplier; /** * Contextual executor based on a context reference. * @author Paul Ferraro */ public class ContextReferenceExecutor<C> implements ContextualExecutor { private final C targetContext; private final ContextReference<C> reference; public ContextReferenceExecutor(C targetContext, ContextReference<C> reference) { this.targetContext = targetContext; this.reference = reference; } @Override public void execute(Runnable runner) { C currentContext = this.reference.get(); this.reference.accept(this.targetContext); try { runner.run(); } finally { this.reference.accept(currentContext); } } @Override public <E extends Exception> void execute(ExceptionRunnable<E> runner) throws E { C currentContext = this.reference.get(); this.reference.accept(this.targetContext); try { runner.run(); } finally { this.reference.accept(currentContext); } } @Override public <T> T execute(Callable<T> caller) throws Exception { C currentContext = this.reference.get(); this.reference.accept(this.targetContext); try { return caller.call(); } finally { this.reference.accept(currentContext); } } @Override public <T> T execute(Supplier<T> supplier) { C currentContext = this.reference.get(); this.reference.accept(this.targetContext); try { return supplier.get(); } finally { this.reference.accept(currentContext); } } @Override public <T, E extends Exception> T execute(ExceptionSupplier<T, E> supplier) throws E { C currentContext = this.reference.get(); this.reference.accept(this.targetContext); try { return supplier.get(); } finally { this.reference.accept(currentContext); } } }
3,235
31.686869
90
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/DefaultContextualizerFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.ServiceLoader; /** * @author Paul Ferraro * */ public enum DefaultContextualizerFactory implements ContextualizerFactory { INSTANCE; private final List<ContextualizerFactory> factories = new LinkedList<>(); DefaultContextualizerFactory() { this.factories.add(new ClassLoaderContextualizerFactory()); for (ContextualizerFactory factory : ServiceLoader.load(ContextualizerFactory.class, ContextualizerFactory.class.getClassLoader())) { this.factories.add(factory); } } @Override public Contextualizer createContextualizer(ClassLoader loader) { List<Contextualizer> contextualizers = new ArrayList<>(this.factories.size()); for (ContextualizerFactory factory : this.factories) { contextualizers.add(factory.createContextualizer(loader)); } return new CompositeContextualizer(contextualizers); } }
2,071
36.672727
141
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/DefaultExecutorService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadFactory; import java.util.function.Function; import org.wildfly.security.ParametricPrivilegedAction; /** * {@link ExecutorService} that performs contextual execution of submitted tasks. * @author Paul Ferraro */ public class DefaultExecutorService extends ContextualExecutorService { public static final ParametricPrivilegedAction<Void, ExecutorService> SHUTDOWN_ACTION = new ParametricPrivilegedAction<>() { @Override public Void run(ExecutorService executor) { executor.shutdown(); return null; } }; public static final ParametricPrivilegedAction<List<Runnable>, ExecutorService> SHUTDOWN_NOW_ACTION = new ParametricPrivilegedAction<>() { @Override public List<Runnable> run(ExecutorService executor) { return executor.shutdownNow(); } }; public DefaultExecutorService(Class<?> targetClass, Function<ThreadFactory, ExecutorService> factory) { super(factory.apply(new DefaultThreadFactory(targetClass)), DefaultContextualizerFactory.INSTANCE.createContextualizer(targetClass)); } }
2,274
38.912281
142
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/Contextualizer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.concurrent.Callable; import java.util.function.Supplier; import org.wildfly.common.function.ExceptionRunnable; import org.wildfly.common.function.ExceptionSupplier; /** * Facility for creating contextual tasks. * @author Paul Ferraro */ public interface Contextualizer { /** * Decorates the specified runner with a given context. * @param runner a runnable task * @return a contextual runner */ Runnable contextualize(Runnable runner); /** * Decorates the specified runner with a given context. * @param <E> the exception type * @param runner a runnable task * @return a contextual runner */ <E extends Exception> ExceptionRunnable<E> contextualize(ExceptionRunnable<E> runner); /** * Decorates the specified caller with a given context. * @param <T> the return type * @param runner a callable task * @return a contextual caller */ <T> Callable<T> contextualize(Callable<T> caller); /** * Decorates the specified supplier with a given context. * @param <T> the return type * @param runner a supplier task * @return a contextual supplier */ <T> Supplier<T> contextualize(Supplier<T> supplier); /** * Decorates the specified supplier with a given context. * @param <T> the return type * @param <E> the exception type * @param runner a supplier task * @return a contextual supplier */ <T, E extends Exception> ExceptionSupplier<T, E> contextualize(ExceptionSupplier<T, E> supplier); }
2,639
33.285714
101
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ClassLoaderContextualizerFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; /** * {@link ContextualizerFactory} that creates a thread context class loader {@link Contextualizer}. * @author Paul Ferraro */ public class ClassLoaderContextualizerFactory implements ContextualizerFactory { @Override public Contextualizer createContextualizer(ClassLoader loader) { return new ContextReferenceExecutor<>(loader, ContextClassLoaderReference.INSTANCE); } }
1,463
39.666667
99
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ContextualExecutorService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; /** * {@link ExecutorService} decorator that contextualizes tasks to be executed. * @author Paul Ferraro */ public class ContextualExecutorService implements ExecutorService { private final ExecutorService executor; private final Contextualizer contextualizer; public ContextualExecutorService(ExecutorService executor, Contextualizer contextualizer) { this.executor = executor; this.contextualizer = contextualizer; } @Override public void execute(Runnable command) { this.executor.execute(this.contextualizer.contextualize(command)); } @Override public void shutdown() { this.executor.shutdown(); } @Override public List<Runnable> shutdownNow() { return this.executor.shutdownNow(); } @Override public boolean isShutdown() { return this.executor.isShutdown(); } @Override public boolean isTerminated() { return this.executor.isTerminated(); } @Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { return this.executor.awaitTermination(timeout, unit); } @Override public <T> Future<T> submit(Callable<T> task) { return this.executor.submit(this.contextualizer.contextualize(task)); } @Override public <T> Future<T> submit(Runnable task, T result) { return this.executor.submit(this.contextualizer.contextualize(task), result); } @Override public Future<?> submit(Runnable task) { return this.executor.submit(this.contextualizer.contextualize(task)); } @Override public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException { return this.executor.invokeAll(this.contextualize(tasks)); } @Override public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException { return this.executor.invokeAll(this.contextualize(tasks), timeout, unit); } @Override public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException { return this.executor.invokeAny(this.contextualize(tasks)); } @Override public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return this.executor.invokeAny(this.contextualize(tasks), timeout, unit); } private <T> Collection<Callable<T>> contextualize(Collection<? extends Callable<T>> tasks) { List<Callable<T>> result = new ArrayList<>(tasks.size()); for (Callable<T> task : tasks) { result.add(this.contextualizer.contextualize(task)); } return result; } }
4,252
33.860656
164
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ExecutorServiceFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import java.util.function.Function; /** * Set of factory implementations for creating an {@link ExecutorService} from a {@link ThreadFactory}. * @author Paul Ferraro */ public enum ExecutorServiceFactory implements Function<ThreadFactory, ExecutorService> { SINGLE_THREAD() { @Override public ExecutorService apply(ThreadFactory factory) { return Executors.newSingleThreadExecutor(factory); } }, CACHED_THREAD() { @Override public ExecutorService apply(ThreadFactory factory) { return Executors.newCachedThreadPool(factory); } }, ; }
1,823
35.48
103
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ContextualThreadFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.concurrent.ThreadFactory; /** * {@link ThreadFactory} decorator that contextualizes its threads. * @author Paul Ferraro */ public class ContextualThreadFactory<C> implements ThreadFactory { private final ThreadFactory factory; private final C targetContext; private final ThreadContextReference<C> reference; private final Contextualizer contextualizer; public ContextualThreadFactory(ThreadFactory factory, C targetContext, ThreadContextReference<C> reference) { this(factory, targetContext, reference, new ContextReferenceExecutor<>(targetContext, reference)); } ContextualThreadFactory(ThreadFactory factory, C targetContext, ThreadContextReference<C> reference, Contextualizer contextualizer) { this.factory = factory; this.targetContext = targetContext; this.reference = reference; this.contextualizer = contextualizer; } @Override public Thread newThread(Runnable task) { Thread thread = this.factory.newThread(this.contextualizer.contextualize(task)); this.reference.accept(thread, this.targetContext); return thread; } }
2,226
39.490909
137
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/ContextualizerFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import org.wildfly.security.manager.WildFlySecurityManager; /** * Factory for creating a {@link Contextualizer} for a {@link ClassLoader}. * @author Paul Ferraro */ public interface ContextualizerFactory { /** * Creates a {@link Contextualizer} for the specified {@link ClassLoader}. * @param loader a class loader * @return a contextualizer */ Contextualizer createContextualizer(ClassLoader loader); /** * Creates a {@link Contextualizer} for the {@link ClassLoader} of the specified {@link Class}. * @param targetClass a class from which to obtain a class loader * @return a contextualizer */ default Contextualizer createContextualizer(Class<?> targetClass) { return this.createContextualizer(WildFlySecurityManager.getClassLoaderPrivileged(targetClass)); } }
1,902
38.645833
103
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/CompositeContextualizer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.Arrays; import java.util.List; import java.util.concurrent.Callable; import java.util.function.Supplier; import org.wildfly.common.function.ExceptionRunnable; import org.wildfly.common.function.ExceptionSupplier; /** * A {@link Contextualizer} decorator that creates contextual tasks from a multiple contextualizers. * @author Paul Ferraro */ public class CompositeContextualizer implements Contextualizer { private final List<Contextualizer> contextualizers; public CompositeContextualizer(Contextualizer... contextualizers) { this(Arrays.asList(contextualizers)); } public CompositeContextualizer(List<Contextualizer> contextualizers) { this.contextualizers = contextualizers; } @Override public Runnable contextualize(Runnable runner) { Runnable result = runner; for (Contextualizer context : this.contextualizers) { result = context.contextualize(result); } return result; } @Override public <E extends Exception> ExceptionRunnable<E> contextualize(ExceptionRunnable<E> runner) { ExceptionRunnable<E> result = runner; for (Contextualizer context : this.contextualizers) { result = context.contextualize(result); } return result; } @Override public <T> Callable<T> contextualize(Callable<T> caller) { Callable<T> result = caller; for (Contextualizer context : this.contextualizers) { result = context.contextualize(result); } return result; } @Override public <T> Supplier<T> contextualize(Supplier<T> supplier) { Supplier<T> result = supplier; for (Contextualizer context : this.contextualizers) { result = context.contextualize(result); } return result; } @Override public <T, E extends Exception> ExceptionSupplier<T, E> contextualize(ExceptionSupplier<T, E> supplier) { ExceptionSupplier<T, E> result = supplier; for (Contextualizer context : this.contextualizers) { result = context.contextualize(result); } return result; } }
3,246
33.542553
109
java
null
wildfly-main/clustering/context/src/main/java/org/wildfly/clustering/context/DefaultThreadFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.context; import java.util.concurrent.ThreadFactory; import org.jboss.threads.JBossThreadFactory; import org.wildfly.security.ParametricPrivilegedAction; import org.wildfly.security.manager.WildFlySecurityManager; /** * Default {@link ThreadFactory} implementation that applies a specific context {@link ClassLoader}. * @author Paul Ferraro */ public class DefaultThreadFactory extends ContextualThreadFactory<ClassLoader> { private enum ThreadPoolFactory implements ParametricPrivilegedAction<ThreadFactory, Class<?>> { INSTANCE; @Override public ThreadFactory run(Class<?> targetClass) { return new JBossThreadFactory(new ThreadGroup(targetClass.getSimpleName()), Boolean.FALSE, null, "%G - %t", null, null); } } public DefaultThreadFactory(Class<?> targetClass) { this(WildFlySecurityManager.doUnchecked(targetClass, ThreadPoolFactory.INSTANCE), targetClass); } public DefaultThreadFactory(ThreadFactory factory) { this(factory, factory.getClass()); } public DefaultThreadFactory(ThreadFactory factory, Class<?> targetClass) { super(factory, WildFlySecurityManager.getClassLoaderPrivileged(targetClass), ContextClassLoaderReference.INSTANCE); } }
2,315
38.931034
132
java
null
wildfly-main/clustering/weld/core/src/test/java/org/wildfly/clustering/weld/BeanManagerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.function.BiFunction; import org.jboss.weld.Container; import org.jboss.weld.bootstrap.api.ServiceRegistry; import org.jboss.weld.config.WeldConfiguration; import org.jboss.weld.event.GlobalObserverNotifierService; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.metadata.TypeStore; import org.jboss.weld.module.ObserverNotifierFactory; import org.jboss.weld.resources.ClassLoaderResourceLoader; import org.jboss.weld.resources.ClassTransformer; import org.jboss.weld.resources.ReflectionCache; import org.jboss.weld.resources.SharedObjectCache; import org.jboss.weld.resources.spi.ResourceLoader; /** * @author Paul Ferraro */ public enum BeanManagerProvider implements BiFunction<String, String, BeanManagerImpl> { INSTANCE; @Override public BeanManagerImpl apply(String containerId, String id) { ServiceRegistry registry = mock(ServiceRegistry.class); WeldConfiguration configuration = mock(WeldConfiguration.class); ObserverNotifierFactory notifierFactory = mock(ObserverNotifierFactory.class); GlobalObserverNotifierService notifierService = mock(GlobalObserverNotifierService.class); ReflectionCache reflectionCache = mock(ReflectionCache.class); ResourceLoader loader = new ClassLoaderResourceLoader(this.getClass().getClassLoader()); SharedObjectCache objectCache = new SharedObjectCache(); TypeStore typeStore = new TypeStore(); when(registry.get(WeldConfiguration.class)).thenReturn(configuration); when(registry.get(ObserverNotifierFactory.class)).thenReturn(notifierFactory); when(registry.get(GlobalObserverNotifierService.class)).thenReturn(notifierService); when(registry.get(SharedObjectCache.class)).thenReturn(objectCache); when(registry.get(ReflectionCache.class)).thenReturn(reflectionCache); when(registry.get(TypeStore.class)).thenReturn(typeStore); when(registry.get(ResourceLoader.class)).thenReturn(loader); when(registry.get(ClassTransformer.class)).thenReturn(new ClassTransformer(typeStore, objectCache, reflectionCache, containerId)); BeanManagerImpl manager = BeanManagerImpl.newRootManager(containerId, id, registry); Container.initialize(containerId, manager, registry); return manager; } }
3,477
46.643836
138
java
null
wildfly-main/clustering/weld/core/src/test/java/org/wildfly/clustering/weld/manager/BeanManagerImplMarshallerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.manager; import java.io.IOException; import org.jboss.weld.manager.BeanManagerImpl; import org.junit.Test; import org.wildfly.clustering.marshalling.Tester; import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; import org.wildfly.clustering.weld.BeanManagerProvider; /** * Validates marshalling of {@link BeanManagerImpl}. * @author Paul Ferraro */ public class BeanManagerImplMarshallerTestCase { @Test public void test() throws IOException { Tester<BeanManagerImpl> tester = ProtoStreamTesterFactory.INSTANCE.createTester(); tester.test(BeanManagerProvider.INSTANCE.apply("foo", "bar")); } }
1,714
37.977273
90
java
null
wildfly-main/clustering/weld/core/src/test/java/org/wildfly/clustering/weld/annotated/slim/AnnotatedTypeMarshallerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import java.io.IOException; import jakarta.enterprise.inject.spi.Annotated; import jakarta.enterprise.inject.spi.AnnotatedConstructor; import jakarta.enterprise.inject.spi.AnnotatedField; import jakarta.enterprise.inject.spi.AnnotatedMethod; import jakarta.enterprise.inject.spi.AnnotatedParameter; import jakarta.enterprise.inject.spi.AnnotatedType; import org.wildfly.clustering.marshalling.Tester; import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; /** * @author Paul Ferraro */ public abstract class AnnotatedTypeMarshallerTestCase { private final Tester<Annotated> tester = ProtoStreamTesterFactory.INSTANCE.createTester(); protected <X> void test(AnnotatedType<X> type) throws IOException { this.tester.test(type); for (AnnotatedConstructor<X> constructor : type.getConstructors()) { this.tester.test(constructor); for (AnnotatedParameter<X> parameter : constructor.getParameters()) { this.tester.test(parameter); } } for (AnnotatedField<? super X> field : type.getFields()) { this.tester.test(field); } for (AnnotatedMethod<? super X> method : type.getMethods()) { this.tester.test(method); for (AnnotatedParameter<? super X> parameter : method.getParameters()) { this.tester.test(parameter); } } } }
2,509
36.462687
94
java
null
wildfly-main/clustering/weld/core/src/test/java/org/wildfly/clustering/weld/annotated/slim/AnnotatedTypeIdentifierMarshallerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import java.io.IOException; import org.jboss.weld.annotated.slim.AnnotatedTypeIdentifier; import org.junit.Test; import org.wildfly.clustering.marshalling.Tester; import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; import org.wildfly.clustering.weld.BeanManagerProvider; /** * Validates marshalling of {@link AnnotatedTypeIdentifier}. * @author Paul Ferraro */ public class AnnotatedTypeIdentifierMarshallerTestCase { @Test public void test() throws IOException { BeanManagerProvider.INSTANCE.apply("foo", "bar"); Tester<AnnotatedTypeIdentifier> tester = ProtoStreamTesterFactory.INSTANCE.createTester(); tester.test(AnnotatedTypeIdentifier.forBackedAnnotatedType("foo", String.class, String.class, "bar")); tester.test(AnnotatedTypeIdentifier.forBackedAnnotatedType("foo", String.class, String.class, "bar", "blah")); tester.test(AnnotatedTypeIdentifier.forModifiedAnnotatedType(AnnotatedTypeIdentifier.forBackedAnnotatedType("foo", String.class, String.class, "bar"))); } }
2,138
44.510638
160
java
null
wildfly-main/clustering/weld/core/src/test/java/org/wildfly/clustering/weld/annotated/slim/backed/BackedAnnotatedTypeMarshallerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim.backed; import java.io.IOException; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedType; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.resources.ReflectionCache; import org.jboss.weld.resources.SharedObjectCache; import org.junit.Test; import org.wildfly.clustering.weld.BeanManagerProvider; import org.wildfly.clustering.weld.annotated.slim.AnnotatedTypeMarshallerTestCase; /** * Validates marshalling of {@link BackedAnnotatedType} and its members. * @author Paul Ferraro */ public class BackedAnnotatedTypeMarshallerTestCase extends AnnotatedTypeMarshallerTestCase { @Test public void test() throws IOException { BeanManagerImpl manager = BeanManagerProvider.INSTANCE.apply("foo", "bar"); SharedObjectCache objectCache = manager.getServices().get(SharedObjectCache.class); ReflectionCache reflectionCache = manager.getServices().get(ReflectionCache.class); this.test(BackedAnnotatedType.of(BackedAnnotatedTypeMarshallerTestCase.class, objectCache, reflectionCache, "foo", "bar")); } }
2,149
42.877551
131
java
null
wildfly-main/clustering/weld/core/src/test/java/org/wildfly/clustering/weld/annotated/slim/unbacked/UnbackedAnnotatedTypeMarshallerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim.unbacked; import java.io.IOException; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedType; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.resources.ClassTransformer; import org.jboss.weld.resources.ReflectionCache; import org.jboss.weld.resources.SharedObjectCache; import org.junit.Test; import org.wildfly.clustering.weld.BeanManagerProvider; import org.wildfly.clustering.weld.annotated.slim.AnnotatedTypeMarshallerTestCase; /** * Validates marshalling of {@link BackedAnnotatedType}. * @author Paul Ferraro */ public class UnbackedAnnotatedTypeMarshallerTestCase extends AnnotatedTypeMarshallerTestCase { @Test public void test() throws IOException { BeanManagerImpl manager = BeanManagerProvider.INSTANCE.apply("foo", "bar"); SharedObjectCache objectCache = manager.getServices().get(SharedObjectCache.class); ReflectionCache reflectionCache = manager.getServices().get(ReflectionCache.class); BackedAnnotatedType<UnbackedAnnotatedTypeMarshallerTestCase> type = BackedAnnotatedType.of(UnbackedAnnotatedTypeMarshallerTestCase.class, objectCache, reflectionCache, "foo", "bar"); ClassTransformer transformer = ClassTransformer.instance(manager); this.test(transformer.getUnbackedAnnotatedType(type, "bar", null)); this.test(transformer.getUnbackedAnnotatedType(type, type)); } }
2,466
45.54717
190
java
null
wildfly-main/clustering/weld/core/src/test/java/org/wildfly/clustering/weld/annotated/slim/unbacked/UnbackedMemberIdentifierMarshallerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim.unbacked; import java.io.IOException; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedType; import org.jboss.weld.annotated.slim.unbacked.UnbackedMemberIdentifier; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.resources.ClassTransformer; import org.jboss.weld.resources.ReflectionCache; import org.jboss.weld.resources.SharedObjectCache; import org.junit.Assert; import org.junit.Test; import org.wildfly.clustering.marshalling.Tester; import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; import org.wildfly.clustering.weld.BeanManagerProvider; /** * Validates marshalling of {@link UnbackedMemberIdentifier}. * @author Paul Ferraro */ public class UnbackedMemberIdentifierMarshallerTestCase { @Test public void test() throws IOException { BeanManagerImpl manager = BeanManagerProvider.INSTANCE.apply("foo", "bar"); SharedObjectCache objectCache = manager.getServices().get(SharedObjectCache.class); ReflectionCache reflectionCache = manager.getServices().get(ReflectionCache.class); BackedAnnotatedType<UnbackedMemberIdentifierMarshallerTestCase> type = BackedAnnotatedType.of(UnbackedMemberIdentifierMarshallerTestCase.class, objectCache, reflectionCache, "foo", "bar"); ClassTransformer transformer = ClassTransformer.instance(manager); Tester<UnbackedMemberIdentifier<UnbackedMemberIdentifierMarshallerTestCase>> tester = ProtoStreamTesterFactory.INSTANCE.createTester(); tester.test(new UnbackedMemberIdentifier<>(transformer.getUnbackedAnnotatedType(type, type), "memberId"), UnbackedMemberIdentifierMarshallerTestCase::assertEquals); } static void assertEquals(UnbackedMemberIdentifier<UnbackedMemberIdentifierMarshallerTestCase> identifier1, UnbackedMemberIdentifier<UnbackedMemberIdentifierMarshallerTestCase> identifier2) { Assert.assertEquals(identifier1.getMemberId(), identifier2.getMemberId()); Assert.assertEquals(identifier1.getType(), identifier2.getType()); } }
3,117
49.290323
196
java
null
wildfly-main/clustering/weld/core/src/test/java/org/wildfly/clustering/weld/bean/StringBeanIdentifierMarshallerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.bean; import java.io.IOException; import org.jboss.weld.bean.StringBeanIdentifier; import org.junit.Test; import org.wildfly.clustering.marshalling.Tester; import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; /** * Validates marshalling of {@link StringBeanIdentifier}. * @author Paul Ferraro */ public class StringBeanIdentifierMarshallerTestCase { @Test public void test() throws IOException { Tester<StringBeanIdentifier> tester = ProtoStreamTesterFactory.INSTANCE.createTester(); tester.test(new StringBeanIdentifier("foo")); } }
1,655
37.511628
95
java
null
wildfly-main/clustering/weld/core/src/test/java/org/wildfly/clustering/weld/bean/ManagedBeanIdentifierMarshallerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.bean; import java.io.IOException; import org.jboss.weld.annotated.slim.AnnotatedTypeIdentifier; import org.jboss.weld.bean.ManagedBeanIdentifier; import org.junit.Test; import org.wildfly.clustering.marshalling.Tester; import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; import org.wildfly.clustering.weld.BeanManagerProvider; /** * Validates marshalling of {@link ManagedBeanIdentifier}. * @author Paul Ferraro */ public class ManagedBeanIdentifierMarshallerTestCase { @Test public void test() throws IOException { BeanManagerProvider.INSTANCE.apply("foo", "bar"); Tester<ManagedBeanIdentifier> tester = ProtoStreamTesterFactory.INSTANCE.createTester(); tester.test(new ManagedBeanIdentifier(AnnotatedTypeIdentifier.forBackedAnnotatedType("foo", String.class, String.class, "bar"))); tester.test(new ManagedBeanIdentifier(AnnotatedTypeIdentifier.forBackedAnnotatedType("foo", String.class, String.class, "bar", "blah"))); tester.test(new ManagedBeanIdentifier(AnnotatedTypeIdentifier.forModifiedAnnotatedType(AnnotatedTypeIdentifier.forBackedAnnotatedType("foo", String.class, String.class, "bar")))); } }
2,253
45.958333
187
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/WeldSerializationContextInitializer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld; import org.infinispan.protostream.SerializationContextInitializer; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.marshalling.protostream.CompositeSerializationContextInitializer; /** * @author Paul Ferraro */ @MetaInfServices(SerializationContextInitializer.class) public class WeldSerializationContextInitializer extends CompositeSerializationContextInitializer { public WeldSerializationContextInitializer() { super(WeldSerializationContextInitializerProvider.class); } }
1,576
39.435897
99
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/WeldSerializationContextInitializerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld; import org.infinispan.protostream.SerializationContextInitializer; import org.wildfly.clustering.marshalling.protostream.ProviderSerializationContextInitializer; import org.wildfly.clustering.marshalling.protostream.SerializationContextInitializerProvider; import org.wildfly.clustering.weld.annotated.slim.SlimAnnotatedMarshallerProvider; import org.wildfly.clustering.weld.annotated.slim.backed.BackedSlimAnnotatedMarshallerProvider; import org.wildfly.clustering.weld.annotated.slim.unbacked.UnbackedSlimAnnotatedMarshallerProvider; import org.wildfly.clustering.weld.bean.BeanMarshallerProvider; import org.wildfly.clustering.weld.bean.builtin.BuiltinBeanMarshallerProvider; import org.wildfly.clustering.weld.bean.proxy.ProxyBeanMarshallerProvider; import org.wildfly.clustering.weld.contexts.ContextsMarshallerProvider; import org.wildfly.clustering.weld.contexts.DistributedContextsMarshallerProvider; import org.wildfly.clustering.weld.contexts.beanstore.BeanStoreMarshallerProvider; import org.wildfly.clustering.weld.injection.InjectionMarshallerProvider; import org.wildfly.clustering.weld.interceptor.proxy.ProxyInterceptorMarshallerProvider; import org.wildfly.clustering.weld.manager.ManagerMarshallerProvider; /** * @author Paul Ferraro */ public enum WeldSerializationContextInitializerProvider implements SerializationContextInitializerProvider { MANAGER(new ProviderSerializationContextInitializer<>("org.jboss.weld.manager.proto", ManagerMarshallerProvider.class)), SLIM_ANNOTATED(new ProviderSerializationContextInitializer<>("org.jboss.weld.annotated.slim.proto", SlimAnnotatedMarshallerProvider.class)), SLIM_BACKED_ANNOTATED(new ProviderSerializationContextInitializer<>("org.jboss.weld.annotated.slim.backed.proto", BackedSlimAnnotatedMarshallerProvider.class)), SLIM_UNBACKED_ANNOTATED(new ProviderSerializationContextInitializer<>("org.jboss.weld.annotated.slim.unbacked.proto", UnbackedSlimAnnotatedMarshallerProvider.class)), BEAN(new ProviderSerializationContextInitializer<>("org.jboss.weld.bean.proto", BeanMarshallerProvider.class)), BUILTIN_BEAN(new ProviderSerializationContextInitializer<>("org.jboss.weld.bean.builtin.proto", BuiltinBeanMarshallerProvider.class)), PROXY_INTERCEPTOR(new ProviderSerializationContextInitializer<>("org.jboss.weld.interceptor.proxy.proto", ProxyInterceptorMarshallerProvider.class)), PROXY_BEAN(new ProviderSerializationContextInitializer<>("org.jboss.weld.bean.proxy.proto", ProxyBeanMarshallerProvider.class)), CONTEXTS(new ProviderSerializationContextInitializer<>("org.jboss.weld.contexts.proto", ContextsMarshallerProvider.class)), DISTRIBUTED_CONTEXTS(new ProviderSerializationContextInitializer<>("org.wildfly.clustering.weld.contexts.proto", DistributedContextsMarshallerProvider.class)), BEAN_STORE(new ProviderSerializationContextInitializer<>("org.jboss.weld.contexts.beanstore.proto", BeanStoreMarshallerProvider.class)), INJECTION(new ProviderSerializationContextInitializer<>("org.jboss.weld.injection.proto", InjectionMarshallerProvider.class)), ; private final SerializationContextInitializer initializer; WeldSerializationContextInitializerProvider(SerializationContextInitializer initializer) { this.initializer = initializer; } @Override public SerializationContextInitializer getInitializer() { return this.initializer; } }
4,472
62
170
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/interceptor/proxy/ProxyInterceptorMarshallerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.interceptor.proxy; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.security.PrivilegedAction; import java.util.Map; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.jboss.weld.interceptor.proxy.InterceptionContext; import org.jboss.weld.interceptor.proxy.InterceptorMethodHandler; import org.jboss.weld.interceptor.spi.model.InterceptionModel; import org.jboss.weld.manager.BeanManagerImpl; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshallerProvider; import org.wildfly.clustering.marshalling.protostream.reflect.TernaryFieldMarshaller; import org.wildfly.clustering.marshalling.protostream.reflect.UnaryFieldMarshaller; import org.wildfly.security.manager.WildFlySecurityManager; /** * @author Paul Ferraro */ public enum ProxyInterceptorMarshallerProvider implements ProtoStreamMarshallerProvider { INTERCEPTOR_CONTEXT(new TernaryFieldMarshaller<>(InterceptionContext.class, Map.class, BeanManagerImpl.class, SlimAnnotatedType.class, (interceptorInstances, manager, annotatedType) -> { InterceptionModel interceptionModel = manager.getInterceptorModelRegistry().get(annotatedType); // How inconvenient. The constructor we need is private... PrivilegedAction<InterceptionContext> action = () -> { try { Constructor<InterceptionContext> constructor = InterceptionContext.class.getDeclaredConstructor(Map.class, BeanManagerImpl.class, InterceptionModel.class, SlimAnnotatedType.class); return constructor.newInstance(interceptorInstances, manager, interceptionModel, annotatedType); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException(e); } }; return WildFlySecurityManager.doUnchecked(action); })), INTERCEPTOR_METHOD_HANDLER(new UnaryFieldMarshaller<>(InterceptorMethodHandler.class, InterceptionContext.class, InterceptorMethodHandler::new)) ; private final ProtoStreamMarshaller<?> marshaller; ProxyInterceptorMarshallerProvider(ProtoStreamMarshaller<?> marshaller) { this.marshaller = marshaller; } @Override public ProtoStreamMarshaller<?> getMarshaller() { return this.marshaller; } }
3,507
47.722222
196
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/manager/ManagerMarshallerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.manager; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshallerProvider; /** * @author Paul Ferraro */ public enum ManagerMarshallerProvider implements ProtoStreamMarshallerProvider { BEAN_MANAGER_IMPL(new BeanManagerImplMarshaller()), ; private final ProtoStreamMarshaller<?> marshaller; ManagerMarshallerProvider(ProtoStreamMarshaller<?> marshaller) { this.marshaller = marshaller; } @Override public ProtoStreamMarshaller<?> getMarshaller() { return this.marshaller; } }
1,687
35.695652
84
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/manager/BeanManagerImplMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.manager; import java.io.IOException; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.Container; import org.jboss.weld.manager.BeanManagerImpl; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * @author Paul Ferraro */ public class BeanManagerImplMarshaller implements ProtoStreamMarshaller<BeanManagerImpl> { private static final int CONTEXT_INDEX = 1; private static final int IDENTIFIER_INDEX = 2; @Override public Class<? extends BeanManagerImpl> getJavaClass() { return BeanManagerImpl.class; } @Override public BeanManagerImpl readFrom(ProtoStreamReader reader) throws IOException { String contextId = null; String id = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case CONTEXT_INDEX: contextId = reader.readString(); break; case IDENTIFIER_INDEX: id = reader.readString(); break; default: reader.skipField(tag); } } return Container.instance(contextId).getBeanManager(id); } @Override public void writeTo(ProtoStreamWriter writer, BeanManagerImpl manager) throws IOException { String contextId = manager.getContextId(); if (contextId != null) { writer.writeString(CONTEXT_INDEX, manager.getContextId()); } String id = manager.getId(); if (id != null) { writer.writeString(IDENTIFIER_INDEX, manager.getId()); } } }
2,905
35.78481
95
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/PassivationCapableSerializableMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import java.io.IOException; import java.util.function.BiFunction; import java.util.function.Function; import jakarta.enterprise.context.spi.Contextual; import jakarta.enterprise.inject.spi.PassivationCapable; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.Container; import org.jboss.weld.serialization.BeanIdentifierIndex; import org.jboss.weld.serialization.spi.BeanIdentifier; import org.jboss.weld.serialization.spi.helpers.SerializableContextual; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * @author Paul Ferraro */ public class PassivationCapableSerializableMarshaller<SC extends SerializableContextual<C, I> & PassivationCapable & MarshallableContextual<C>, C extends Contextual<I> & PassivationCapable, I> implements ProtoStreamMarshaller<SC> { private static final int CONTEXT_INDEX = 1; private static final int CONTEXTUAL_INDEX = 2; private static final int IDENTIFIER_INDEX = 3; private static final int INDEX_INDEX = 4; private final Class<SC> targetClass; private final BiFunction<String, C, SC> resolvedFactory; private final BiFunction<String, BeanIdentifier, SC> unresolvedFactory; private final Function<SC, String> contextFunction; PassivationCapableSerializableMarshaller(Class<SC> targetClass, BiFunction<String, C, SC> resolvedFactory, BiFunction<String, BeanIdentifier, SC> unresolvedFactory, Function<SC, String> contextFunction) { this.targetClass = targetClass; this.resolvedFactory = resolvedFactory; this.unresolvedFactory = unresolvedFactory; this.contextFunction = contextFunction; } @Override public Class<SC> getJavaClass() { return this.targetClass; } @SuppressWarnings("unchecked") @Override public SC readFrom(ProtoStreamReader reader) throws IOException { String contextId = null; C contextual = null; BeanIdentifier identifier = null; int beanIndex = 0; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case CONTEXT_INDEX: contextId = reader.readAny(String.class); break; case CONTEXTUAL_INDEX: contextual = (C) reader.readAny(); break; case IDENTIFIER_INDEX: identifier = reader.readAny(BeanIdentifier.class); break; case INDEX_INDEX: beanIndex = reader.readUInt32(); break; default: reader.skipField(tag); } } if (contextual != null) { return this.resolvedFactory.apply(contextId, contextual); } if (identifier == null) { BeanIdentifierIndex index = Container.instance(contextId).services().get(BeanIdentifierIndex.class); identifier = index.getIdentifier(beanIndex); } return this.unresolvedFactory.apply(contextId, identifier); } @Override public void writeTo(ProtoStreamWriter writer, SC contextual) throws IOException { String contextId = this.contextFunction.apply(contextual); writer.writeAny(CONTEXT_INDEX, this.contextFunction.apply(contextual)); C instance = contextual.getInstance(); if ((instance != null) && writer.getSerializationContext().canMarshall(instance)) { writer.writeAny(CONTEXTUAL_INDEX, instance); } else { BeanIdentifier identifier = contextual.getIdentifier(); BeanIdentifierIndex index = Container.instance(contextId).services().get(BeanIdentifierIndex.class); Integer beanIndex = (index != null) && index.isBuilt() ? index.getIndex(identifier) : null; if (beanIndex != null) { int value = beanIndex.intValue(); if (value != 0) { writer.writeUInt32(INDEX_INDEX, value); } } else { writer.writeAny(IDENTIFIER_INDEX, identifier); } } } }
5,406
41.912698
231
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/PassivationCapableSerializableContextual.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import java.io.ObjectStreamException; import java.io.Serializable; import jakarta.enterprise.context.spi.Contextual; import jakarta.enterprise.inject.spi.PassivationCapable; import org.jboss.weld.Container; import org.jboss.weld.bean.WrappedContextual; import org.jboss.weld.contexts.ForwardingContextual; import org.jboss.weld.serialization.spi.BeanIdentifier; import org.jboss.weld.serialization.spi.ContextualStore; import org.jboss.weld.util.Beans; /** * @author Paul Ferraro */ public class PassivationCapableSerializableContextual<C extends Contextual<I> & PassivationCapable, I> extends ForwardingContextual<I> implements PassivationCapableContextual<C, I>, WrappedContextual<I>, MarshallableContextual<C> { private static final long serialVersionUID = 5113888683790476497L; private final String contextId; private final BeanIdentifier identifier; private C instance; public PassivationCapableSerializableContextual(String contextId, C instance) { this(contextId, Beans.getIdentifier(instance, Container.instance(contextId).services().get(ContextualStore.class)), instance); } PassivationCapableSerializableContextual(String contextId, BeanIdentifier identifier) { this(contextId, identifier, null); } private PassivationCapableSerializableContextual(String contextId, BeanIdentifier identifier, C instance) { this.contextId = contextId; this.identifier = identifier; this.instance = instance; } @Override public BeanIdentifier getIdentifier() { return this.identifier; } @Override public C getInstance() { return this.instance; } @Override public String getId() { return this.get().getId(); } @Override public C get() { // Resolve contextual lazily if (this.instance == null) { Container container = Container.instance(this.contextId); ContextualStore store = container.services().get(ContextualStore.class); this.instance = store.getContextual(this.identifier); } return this.instance; } @Override public Contextual<I> delegate() { return this.get(); } @Override public String getContextId() { return this.contextId; } @SuppressWarnings("unused") private Object writeReplace() throws ObjectStreamException { return (this.instance instanceof Serializable) ? this : new PassivationCapableSerializableContextualProxy<>(this.contextId, this.identifier); } }
3,630
34.252427
231
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/PassivationCapableSerializableBeanMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import jakarta.enterprise.inject.spi.Bean; import jakarta.enterprise.inject.spi.PassivationCapable; /** * @author Paul Ferraro */ public class PassivationCapableSerializableBeanMarshaller<B extends Bean<I> & PassivationCapable, I> extends PassivationCapableSerializableMarshaller<PassivationCapableSerializableBean<B, I>, B, I> { @SuppressWarnings("unchecked") PassivationCapableSerializableBeanMarshaller() { super((Class<PassivationCapableSerializableBean<B, I>>) (Class<?>) PassivationCapableSerializableBean.class, PassivationCapableSerializableBean::new, PassivationCapableSerializableBean::new, PassivationCapableSerializableBean::getContextId); } }
1,751
45.105263
249
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/PassivationCapableSerializableBeanProxy.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import java.io.ObjectStreamException; import jakarta.enterprise.inject.spi.Bean; import jakarta.enterprise.inject.spi.PassivationCapable; import org.jboss.weld.serialization.spi.BeanIdentifier; /** * @author Paul Ferraro */ public class PassivationCapableSerializableBeanProxy<B extends Bean<I> & PassivationCapable, I> extends PassivationCapableSerializableProxy { private static final long serialVersionUID = -6265576522828887136L; PassivationCapableSerializableBeanProxy(String contextId, BeanIdentifier identifier) { super(contextId, identifier); } @SuppressWarnings("unused") private Object readResolve() throws ObjectStreamException { return new PassivationCapableSerializableBean<>(this.getContextId(), this.getIdentifier()); } }
1,855
38.489362
141
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/PassivationCapableContextual.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import jakarta.enterprise.context.spi.Contextual; import jakarta.enterprise.inject.spi.PassivationCapable; import org.jboss.weld.serialization.spi.helpers.SerializableContextual; /** * @author Paul Ferraro */ public interface PassivationCapableContextual<C extends Contextual<I> & PassivationCapable, I> extends SerializableContextual<C, I>, PassivationCapable { /** * Returns the identifier of this context. * @return a context identifier. */ String getContextId(); }
1,568
37.268293
153
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/ContextsMarshallerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshallerProvider; /** * @author Paul Ferraro */ public enum ContextsMarshallerProvider implements ProtoStreamMarshallerProvider { CREATIONAL_CONTEXT_IMPL(new CreationalContextImplMarshaller<>()), SERIALIZABLE_CONTEXTUAL_INSTANCE(new SerializableContextualInstanceImplMarshaller<>()), ; private final ProtoStreamMarshaller<?> marshaller; ContextsMarshallerProvider(ProtoStreamMarshaller<?> marshaller) { this.marshaller = marshaller; } @Override public ProtoStreamMarshaller<?> getMarshaller() { return this.marshaller; } }
1,796
37.234043
91
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/PassivationCapableSerializableBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import java.io.ObjectStreamException; import java.io.Serializable; import jakarta.enterprise.inject.spi.Bean; import jakarta.enterprise.inject.spi.PassivationCapable; import org.jboss.weld.Container; import org.jboss.weld.bean.ForwardingBean; import org.jboss.weld.serialization.spi.BeanIdentifier; import org.jboss.weld.serialization.spi.ContextualStore; import org.jboss.weld.util.Beans; /** * @author Paul Ferraro */ public class PassivationCapableSerializableBean<B extends Bean<I> & PassivationCapable, I> extends ForwardingBean<I> implements PassivationCapableContextual<B, I>, MarshallableContextual<B> { private static final long serialVersionUID = -840179425829721439L; private final String contextId; private final BeanIdentifier identifier; private B instance; public PassivationCapableSerializableBean(String contextId, B instance) { this(contextId, Beans.getIdentifier(instance, Container.instance(contextId).services().get(ContextualStore.class)), instance); } PassivationCapableSerializableBean(String contextId, BeanIdentifier identifier) { this(contextId, identifier, null); } private PassivationCapableSerializableBean(String contextId, BeanIdentifier identifier, B instance) { this.contextId = contextId; this.instance = instance; this.identifier = identifier; } @Override public BeanIdentifier getIdentifier() { return this.identifier; } @Override public B getInstance() { return this.instance; } @Override public String getId() { return this.instance.getId(); } @Override public B get() { // Resolve contextual lazily if (this.instance == null) { Container container = Container.instance(this.contextId); ContextualStore store = container.services().get(ContextualStore.class); this.instance = store.getContextual(this.identifier); } return this.instance; } @Override public Bean<I> delegate() { return this.get(); } @Override public String getContextId() { return this.contextId; } @SuppressWarnings("unused") private Object writeReplace() throws ObjectStreamException { return (this.instance instanceof Serializable) ? this : new PassivationCapableSerializableContextualProxy<>(this.contextId, this.identifier); } }
3,506
33.382353
191
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/PassivationCapableSerializableContextualProxy.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import java.io.ObjectStreamException; import jakarta.enterprise.context.spi.Contextual; import jakarta.enterprise.inject.spi.PassivationCapable; import org.jboss.weld.serialization.spi.BeanIdentifier; /** * @author Paul Ferraro */ public class PassivationCapableSerializableContextualProxy<C extends Contextual<I> & PassivationCapable, I> extends PassivationCapableSerializableProxy { private static final long serialVersionUID = -5640463865738900184L; PassivationCapableSerializableContextualProxy(String contextId, BeanIdentifier identifier) { super(contextId, identifier); } @SuppressWarnings("unused") private Object readResolve() throws ObjectStreamException { return new PassivationCapableSerializableContextual<>(this.getContextId(), this.getIdentifier()); } }
1,886
39.148936
153
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/CreationalContextImplMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import java.io.IOException; import java.lang.reflect.Field; import java.security.PrivilegedAction; import java.util.LinkedList; import java.util.List; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.context.api.ContextualInstance; import org.jboss.weld.contexts.CreationalContextImpl; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; import org.wildfly.security.manager.WildFlySecurityManager; /** * @author Paul Ferraro */ public class CreationalContextImplMarshaller<T> implements ProtoStreamMarshaller<CreationalContextImpl<T>> { private static final int PARENT_INDEX = 1; private static final int DEPENDENT_INDEX = 2; static final Field PARENT_FIELD = WildFlySecurityManager.doUnchecked(new PrivilegedAction<Field>() { @Override public Field run() { for (Field field : CreationalContextImpl.class.getDeclaredFields()) { if (field.getType() == CreationalContextImpl.class) { field.setAccessible(true); return field; } } throw new IllegalStateException(); } }); @SuppressWarnings("unchecked") @Override public Class<? extends CreationalContextImpl<T>> getJavaClass() { return (Class<CreationalContextImpl<T>>) (Class<?>) CreationalContextImpl.class; } @Override public CreationalContextImpl<T> readFrom(ProtoStreamReader reader) throws IOException { CreationalContextImpl<T> result = new CreationalContextImpl<>(null); reader.getContext().record(result); while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case PARENT_INDEX: CreationalContextImpl<?> parent = reader.readAny(CreationalContextImpl.class); WildFlySecurityManager.doUnchecked(new PrivilegedAction<Void>() { @Override public Void run() { try { PARENT_FIELD.set(result, parent); return null; } catch (IllegalAccessException e) { throw new IllegalStateException(e); } } }); for (ContextualInstance<?> dependent : parent.getDependentInstances()) { result.addDependentInstance(dependent); } break; case DEPENDENT_INDEX: ContextualInstance<?> dependent = reader.readAny(ContextualInstance.class); result.getCreationalContext(null).addDependentInstance(dependent); break; default: reader.skipField(tag); } } return result; } @SuppressWarnings("unchecked") @Override public void writeTo(ProtoStreamWriter writer, CreationalContextImpl<T> context) throws IOException { writer.getContext().record(context); CreationalContextImpl<?> parent = context.getParentCreationalContext(); if (parent != null) { writer.writeAny(PARENT_INDEX, parent); } // https://issues.jboss.org/browse/WELD-1076 // Mimics CreationalContextImpl.writeReplace(...) List<Object> unmarshallableDependents = new LinkedList<>(); for (ContextualInstance<?> dependent : context.getDependentInstances()) { Object dependentInstance = dependent.getInstance(); if (writer.getSerializationContext().canMarshall(dependentInstance)) { writer.writeAny(DEPENDENT_INDEX, dependent); } else { unmarshallableDependents.add(dependentInstance); } } // Destroy unmarshallable dependents outside of loop - otherwise it will throw a ConcurrentModificationException for (Object dependentInstance : unmarshallableDependents) { context.destroyDependentInstance((T) dependentInstance); } } }
5,424
42.055556
120
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/PassivationCapableSerializableProxy.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import java.io.Serializable; import org.jboss.weld.Container; import org.jboss.weld.serialization.BeanIdentifierIndex; import org.jboss.weld.serialization.spi.BeanIdentifier; /** * Serialization proxy for passivation capable contextuals that are not serializable. * @author Paul Ferraro */ public abstract class PassivationCapableSerializableProxy implements Serializable { private static final long serialVersionUID = 4906800089125597758L; private final String contextId; private final BeanIdentifier identifier; private final Integer beanIndex; PassivationCapableSerializableProxy(String contextId, BeanIdentifier identifier) { this.contextId = contextId; BeanIdentifierIndex index = Container.instance(contextId).services().get(BeanIdentifierIndex.class); this.beanIndex = (index != null) && index.isBuilt() ? index.getIndex(identifier) : null; this.identifier = (this.beanIndex == null) ? identifier : null; } String getContextId() { return this.contextId; } BeanIdentifier getIdentifier() { return (this.identifier != null) ? this.identifier : Container.instance(this.contextId).services().get(BeanIdentifierIndex.class).getIdentifier(this.beanIndex); } }
2,329
39.877193
168
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/PassivationCapableSerializableContextualMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import jakarta.enterprise.context.spi.Contextual; import jakarta.enterprise.inject.spi.PassivationCapable; /** * @author Paul Ferraro */ public class PassivationCapableSerializableContextualMarshaller<C extends Contextual<I> & PassivationCapable, I> extends PassivationCapableSerializableMarshaller<PassivationCapableSerializableContextual<C, I>, C, I> { @SuppressWarnings("unchecked") PassivationCapableSerializableContextualMarshaller() { super((Class<PassivationCapableSerializableContextual<C, I>>) (Class<?>) PassivationCapableSerializableContextual.class, PassivationCapableSerializableContextual::new, PassivationCapableSerializableContextual::new, PassivationCapableSerializableContextual::getContextId); } }
1,812
46.710526
279
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/SerializableContextualInstanceImplMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import java.io.IOException; import java.security.PrivilegedAction; import jakarta.enterprise.context.spi.Contextual; import jakarta.enterprise.context.spi.CreationalContext; import jakarta.enterprise.inject.spi.PassivationCapable; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.Container; import org.jboss.weld.bean.proxy.MethodHandler; import org.jboss.weld.bean.proxy.ProxyInstantiator; import org.jboss.weld.bean.proxy.ProxyObject; import org.jboss.weld.contexts.SerializableContextualInstanceImpl; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; import org.wildfly.security.manager.WildFlySecurityManager; /** * @author Paul Ferraro */ public class SerializableContextualInstanceImplMarshaller<C extends Contextual<I> & PassivationCapable, I> implements ProtoStreamMarshaller<SerializableContextualInstanceImpl<C, I>> { private static final int CONTEXTUAL_INDEX = 1; private static final int INSTANCE_INDEX = 2; private static final int PROXY_CLASS_INDEX = 3; private static final int METHOD_HANDLER_INDEX = 4; private static final int CREATIONAL_CONTEXT_INDEX = 5; @SuppressWarnings("unchecked") @Override public Class<? extends SerializableContextualInstanceImpl<C, I>> getJavaClass() { return (Class<SerializableContextualInstanceImpl<C, I>>) (Class<?>) SerializableContextualInstanceImpl.class; } @SuppressWarnings("unchecked") @Override public SerializableContextualInstanceImpl<C, I> readFrom(ProtoStreamReader reader) throws IOException { PassivationCapableContextual<C, I> contextual = null; I instance = null; CreationalContext<I> creationalContext = null; Class<?> proxyClass = null; MethodHandler handler = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case CONTEXTUAL_INDEX: contextual = reader.readAny(PassivationCapableContextual.class); break; case INSTANCE_INDEX: instance = (I) reader.readAny(); break; case PROXY_CLASS_INDEX: proxyClass = reader.readObject(Class.class); break; case METHOD_HANDLER_INDEX: handler = reader.readAny(MethodHandler.class); break; case CREATIONAL_CONTEXT_INDEX: creationalContext = reader.readAny(CreationalContext.class); break; default: reader.skipField(tag); } } if (proxyClass != null) { Class<?> targetClass = proxyClass; ProxyInstantiator instantiator = Container.instance(contextual.getContextId()).services().get(ProxyInstantiator.class); PrivilegedAction<I> action = new PrivilegedAction<>() { @Override public I run() { try { return (I) instantiator.newInstance(targetClass); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } } }; instance = WildFlySecurityManager.doUnchecked(action); if (handler != null) { ((ProxyObject) instance).weld_setHandler(handler); } } return new SerializableContextualInstanceImpl<>(contextual, instance, creationalContext); } @Override public void writeTo(ProtoStreamWriter writer, SerializableContextualInstanceImpl<C, I> contextualInstance) throws IOException { writer.writeAny(CONTEXTUAL_INDEX, contextualInstance.getContextual()); Object instance = contextualInstance.getInstance(); // If this is a weld proxy, marshal class and method handler if (instance instanceof ProxyObject) { writer.writeObject(PROXY_CLASS_INDEX, instance.getClass()); writer.writeAny(METHOD_HANDLER_INDEX, ((ProxyObject) instance).weld_getHandler()); } else { writer.writeAny(INSTANCE_INDEX, instance); } writer.writeAny(CREATIONAL_CONTEXT_INDEX, contextualInstance.getCreationalContext()); } }
5,611
43.896
183
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/DistributedContextsMarshallerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshallerProvider; /** * @author Paul Ferraro */ public enum DistributedContextsMarshallerProvider implements ProtoStreamMarshallerProvider { PASSIVATION_CAPABLE_SERIALIZABLE_BEAN(new PassivationCapableSerializableBeanMarshaller<>()), PASSIVATION_CAPABLE_SERIALIZABLE_CONTEXTUAL(new PassivationCapableSerializableContextualMarshaller<>()), ; private final ProtoStreamMarshaller<?> marshaller; DistributedContextsMarshallerProvider(ProtoStreamMarshaller<?> marshaller) { this.marshaller = marshaller; } @Override public ProtoStreamMarshaller<?> getMarshaller() { return this.marshaller; } }
1,862
38.638298
108
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/MarshallableContextual.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts; import org.jboss.weld.serialization.spi.BeanIdentifier; /** * @author Paul Ferraro */ public interface MarshallableContextual<C> { BeanIdentifier getIdentifier(); C getInstance(); }
1,266
34.194444
70
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/contexts/beanstore/BeanStoreMarshallerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.contexts.beanstore; import org.jboss.weld.contexts.beanstore.LockStore; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshallerProvider; import org.wildfly.clustering.marshalling.protostream.ValueMarshaller; /** * @author Paul Ferraro */ public enum BeanStoreMarshallerProvider implements ProtoStreamMarshallerProvider { LOCK_STORE(new ValueMarshaller<>(LockStore::new)), ; private final ProtoStreamMarshaller<?> marshaller; BeanStoreMarshallerProvider(ProtoStreamMarshaller<?> marshaller) { this.marshaller = marshaller; } @Override public ProtoStreamMarshaller<?> getMarshaller() { return this.marshaller; } }
1,823
37.808511
84
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/injection/ParameterInjectionPointMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.injection; import java.io.IOException; import java.lang.reflect.Method; import jakarta.enterprise.inject.spi.AnnotatedConstructor; import jakarta.enterprise.inject.spi.AnnotatedMethod; import jakarta.enterprise.inject.spi.Bean; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.Container; import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedCallable; import org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedConstructorImpl; import org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedMethodImpl; import org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedParameterImpl; import org.jboss.weld.annotated.slim.AnnotatedTypeIdentifier; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedCallable; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedParameter; import org.jboss.weld.injection.InjectionPointFactory; import org.jboss.weld.injection.ParameterInjectionPoint; import org.jboss.weld.injection.ParameterInjectionPointImpl; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.resources.ClassTransformer; import org.jboss.weld.serialization.spi.BeanIdentifier; import org.jboss.weld.serialization.spi.ContextualStore; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * @author Paul Ferraro */ public class ParameterInjectionPointMarshaller<T, X> implements ProtoStreamMarshaller<ParameterInjectionPointImpl<T, X>> { private static final int PARAMETER_INDEX = 1; private static final int BEAN_INDEX = 2; @SuppressWarnings("unchecked") @Override public Class<? extends ParameterInjectionPointImpl<T, X>> getJavaClass() { return (Class<ParameterInjectionPointImpl<T, X>>) (Class<?>) ParameterInjectionPoint.class; } @SuppressWarnings("unchecked") @Override public ParameterInjectionPointImpl<T, X> readFrom(ProtoStreamReader reader) throws IOException { BackedAnnotatedParameter<X> parameter = null; BeanIdentifier beanId = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case PARAMETER_INDEX: parameter = reader.readObject(BackedAnnotatedParameter.class); break; case BEAN_INDEX: beanId = reader.readAny(BeanIdentifier.class); break; default: reader.skipField(tag); } } BackedAnnotatedCallable<X, ?> callable = parameter.getDeclaringCallable(); SlimAnnotatedType<X> type = callable.getDeclaringType(); AnnotatedTypeIdentifier identifier = type.getIdentifier(); BeanManagerImpl manager = Container.instance(identifier).getBeanManager(identifier.getBdaId()); ClassTransformer transformer = ClassTransformer.instance(manager); Bean<?> bean = (beanId != null) ? Container.instance(manager).services().get(ContextualStore.class).<Bean<Object>, Object>getContextual(beanId) : null; EnhancedAnnotatedCallable<?, X, ?> enhancedCallable = (callable.getJavaMember() instanceof Method) ? EnhancedAnnotatedMethodImpl.of((AnnotatedMethod<X>) callable, transformer.getEnhancedAnnotatedType(type), transformer) : EnhancedAnnotatedConstructorImpl.of((AnnotatedConstructor<X>) callable, transformer.getEnhancedAnnotatedType(type), transformer); return (ParameterInjectionPointImpl<T, X>) InjectionPointFactory.silentInstance().createParameterInjectionPoint(EnhancedAnnotatedParameterImpl.<T, X>of(parameter, enhancedCallable, transformer), bean, getJavaClass(), manager); } @Override public void writeTo(ProtoStreamWriter writer, ParameterInjectionPointImpl<T, X> injectionPoint) throws IOException { BackedAnnotatedParameter<X> parameter = (BackedAnnotatedParameter<X>) injectionPoint.getAnnotated(); if (parameter != null) { writer.writeObject(PARAMETER_INDEX, parameter); } Bean<?> bean = injectionPoint.getBean(); if (bean != null) { BeanIdentifier beanId = Container.instance(parameter.getDeclaringCallable().getDeclaringType().getIdentifier()).services().get(ContextualStore.class).putIfAbsent(bean); writer.writeAny(BEAN_INDEX, beanId); } } }
5,597
50.833333
359
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/injection/FieldInjectionPointMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.injection; import java.io.IOException; import jakarta.enterprise.inject.spi.Bean; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.Container; import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedField; import org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedFieldImpl; import org.jboss.weld.annotated.slim.AnnotatedTypeIdentifier; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedField; import org.jboss.weld.injection.FieldInjectionPoint; import org.jboss.weld.injection.InjectionPointFactory; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.resources.ClassTransformer; import org.jboss.weld.serialization.spi.BeanIdentifier; import org.jboss.weld.serialization.spi.ContextualStore; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * @author Paul Ferraro */ public class FieldInjectionPointMarshaller<T, X> implements ProtoStreamMarshaller<FieldInjectionPoint<T, X>> { private static final int FIELD_INDEX = 1; private static final int BEAN_INDEX = 2; @SuppressWarnings("unchecked") @Override public Class<? extends FieldInjectionPoint<T, X>> getJavaClass() { return (Class<FieldInjectionPoint<T, X>>) (Class<?>) FieldInjectionPoint.class; } @SuppressWarnings("unchecked") @Override public FieldInjectionPoint<T, X> readFrom(ProtoStreamReader reader) throws IOException { BackedAnnotatedField<X> field = null; BeanIdentifier beanId = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case FIELD_INDEX: field = reader.readObject(BackedAnnotatedField.class); break; case BEAN_INDEX: beanId = reader.readAny(BeanIdentifier.class); break; default: reader.skipField(tag); } } SlimAnnotatedType<X> type = field.getDeclaringType(); AnnotatedTypeIdentifier identifier = type.getIdentifier(); BeanManagerImpl manager = Container.instance(identifier).getBeanManager(identifier.getBdaId()); ClassTransformer transformer = ClassTransformer.instance(manager); Bean<?> bean = (beanId != null) ? Container.instance(manager).services().get(ContextualStore.class).<Bean<Object>, Object>getContextual(beanId) : null; EnhancedAnnotatedField<T, X> enhancedField = (EnhancedAnnotatedField<T, X>) EnhancedAnnotatedFieldImpl.of(field, transformer.getEnhancedAnnotatedType(type), transformer); return InjectionPointFactory.silentInstance().createFieldInjectionPoint(enhancedField, bean, type.getJavaClass(), manager); } @Override public void writeTo(ProtoStreamWriter writer, FieldInjectionPoint<T, X> injectionPoint) throws IOException { BackedAnnotatedField<X> field = (BackedAnnotatedField<X>) injectionPoint.getAnnotated(); if (field != null) { writer.writeObject(FIELD_INDEX, field); } Bean<?> bean = injectionPoint.getBean(); if (bean != null) { BeanIdentifier beanId = Container.instance(field.getDeclaringType().getIdentifier()).services().get(ContextualStore.class).putIfAbsent(bean); writer.writeAny(BEAN_INDEX, beanId); } } }
4,660
45.61
178
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/injection/InjectionMarshallerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.injection; import org.jboss.weld.injection.EmptyInjectionPoint; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshallerProvider; import org.wildfly.clustering.marshalling.protostream.ValueMarshaller; /** * @author Paul Ferraro */ public enum InjectionMarshallerProvider implements ProtoStreamMarshallerProvider { CONSTRUCTOR(new ConstructorInjectionPointMarshaller<>()), EMPTY(new ValueMarshaller<>(EmptyInjectionPoint.INSTANCE)), FIELD(new FieldInjectionPointMarshaller<>()), METHOD(new MethodInjectionPointMarshaller<>()), PARAMETER(new ParameterInjectionPointMarshaller<>()), ; private final ProtoStreamMarshaller<?> marshaller; InjectionMarshallerProvider(ProtoStreamMarshaller<?> marshaller) { this.marshaller = marshaller; } @Override public ProtoStreamMarshaller<?> getMarshaller() { return this.marshaller; } }
2,047
38.384615
84
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/injection/ConstructorInjectionPointMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.injection; import java.io.IOException; import jakarta.enterprise.inject.spi.Bean; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.Container; import org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedConstructorImpl; import org.jboss.weld.annotated.slim.AnnotatedTypeIdentifier; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedConstructor; import org.jboss.weld.injection.ConstructorInjectionPoint; import org.jboss.weld.injection.InjectionPointFactory; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.resources.ClassTransformer; import org.jboss.weld.serialization.spi.BeanIdentifier; import org.jboss.weld.serialization.spi.ContextualStore; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * @author Paul Ferraro */ public class ConstructorInjectionPointMarshaller<X> implements ProtoStreamMarshaller<ConstructorInjectionPoint<X>> { private static final int CONSTRUCTOR_INDEX = 1; private static final int BEAN_INDEX = 2; @SuppressWarnings("unchecked") @Override public Class<? extends ConstructorInjectionPoint<X>> getJavaClass() { return (Class<ConstructorInjectionPoint<X>>) (Class<?>) ConstructorInjectionPoint.class; } @Override public ConstructorInjectionPoint<X> readFrom(ProtoStreamReader reader) throws IOException { BackedAnnotatedConstructor<X> constructor = null; BeanIdentifier beanId = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case CONSTRUCTOR_INDEX: constructor = reader.readObject(BackedAnnotatedConstructor.class); break; case BEAN_INDEX: beanId = reader.readAny(BeanIdentifier.class); break; default: reader.skipField(tag); } } SlimAnnotatedType<X> type = constructor.getDeclaringType(); AnnotatedTypeIdentifier identifier = type.getIdentifier(); BeanManagerImpl manager = Container.instance(identifier).getBeanManager(identifier.getBdaId()); ClassTransformer transformer = ClassTransformer.instance(manager); Bean<X> bean = (beanId != null) ? Container.instance(manager).services().get(ContextualStore.class).<Bean<X>, X>getContextual(beanId) : null; return InjectionPointFactory.silentInstance().createConstructorInjectionPoint(bean, type.getJavaClass(), EnhancedAnnotatedConstructorImpl.of(constructor, transformer.getEnhancedAnnotatedType(type), transformer), manager); } @Override public void writeTo(ProtoStreamWriter writer, ConstructorInjectionPoint<X> injectionPoint) throws IOException { BackedAnnotatedConstructor<X> constructor = (BackedAnnotatedConstructor<X>) injectionPoint.getAnnotated(); if (constructor != null) { writer.writeObject(CONSTRUCTOR_INDEX, constructor); } Bean<?> bean = injectionPoint.getBean(); if (bean != null) { BeanIdentifier beanId = Container.instance(constructor.getDeclaringType().getIdentifier()).services().get(ContextualStore.class).putIfAbsent(bean); writer.writeAny(BEAN_INDEX, beanId); } } }
4,595
46.381443
229
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/injection/MethodInjectionPointMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.injection; import java.io.IOException; import java.lang.reflect.Field; import java.security.PrivilegedAction; import java.util.Collections; import jakarta.enterprise.inject.spi.Bean; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.Container; import org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedMethodImpl; import org.jboss.weld.annotated.slim.AnnotatedTypeIdentifier; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedMethod; import org.jboss.weld.injection.InjectionPointFactory; import org.jboss.weld.injection.MethodInjectionPoint; import org.jboss.weld.injection.MethodInjectionPoint.MethodInjectionPointType; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.resources.ClassTransformer; import org.jboss.weld.serialization.spi.BeanIdentifier; import org.jboss.weld.serialization.spi.ContextualStore; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; import org.wildfly.security.manager.WildFlySecurityManager; /** * @author Paul Ferraro */ public class MethodInjectionPointMarshaller<T, X> implements ProtoStreamMarshaller<MethodInjectionPoint<T, X>> { private static final int TYPE_INDEX = 1; private static final int METHOD_INDEX = 2; private static final int BEAN_INDEX = 3; private static final MethodInjectionPointType DEFAULT_TYPE = MethodInjectionPointType.PRODUCER; static final Field TYPE_FIELD = WildFlySecurityManager.doUnchecked(new PrivilegedAction<Field>() { @Override public Field run() { for (Field field : MethodInjectionPoint.class.getDeclaredFields()) { if (field.getType() == MethodInjectionPointType.class) { field.setAccessible(true); return field; } } throw new IllegalStateException(); } }); @SuppressWarnings("unchecked") @Override public Class<? extends MethodInjectionPoint<T, X>> getJavaClass() { return (Class<MethodInjectionPoint<T, X>>) (Class<?>) MethodInjectionPoint.class; } @Override public MethodInjectionPoint<T, X> readFrom(ProtoStreamReader reader) throws IOException { MethodInjectionPointType injectionPointType = DEFAULT_TYPE; BackedAnnotatedMethod<X> method = null; BeanIdentifier beanId = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case TYPE_INDEX: injectionPointType = reader.readEnum(MethodInjectionPointType.class); case METHOD_INDEX: method = reader.readObject(BackedAnnotatedMethod.class); break; case BEAN_INDEX: beanId = reader.readAny(BeanIdentifier.class); break; default: reader.skipField(tag); } } SlimAnnotatedType<X> type = method.getDeclaringType(); AnnotatedTypeIdentifier identifier = type.getIdentifier(); BeanManagerImpl manager = Container.instance(identifier).getBeanManager(identifier.getBdaId()); ClassTransformer transformer = ClassTransformer.instance(manager); Bean<X> bean = (beanId != null) ? Container.instance(manager).services().get(ContextualStore.class).<Bean<X>, X>getContextual(beanId) : null; return InjectionPointFactory.silentInstance().createMethodInjectionPoint(injectionPointType, EnhancedAnnotatedMethodImpl.of(method, transformer.getEnhancedAnnotatedType(type), transformer), bean, getJavaClass(), Collections.emptySet(), manager); } @Override public void writeTo(ProtoStreamWriter writer, MethodInjectionPoint<T, X> injectionPoint) throws IOException { MethodInjectionPointType type = this.getValue(injectionPoint, TYPE_FIELD, MethodInjectionPointType.class); if (type != DEFAULT_TYPE) { writer.writeEnum(TYPE_INDEX, type); } BackedAnnotatedMethod<X> method = (BackedAnnotatedMethod<X>) injectionPoint.getAnnotated(); if (method != null) { writer.writeObject(METHOD_INDEX, method); } Bean<?> bean = injectionPoint.getBean(); if (bean != null) { BeanIdentifier beanId = Container.instance(method.getDeclaringType().getIdentifier()).services().get(ContextualStore.class).putIfAbsent(bean); writer.writeAny(BEAN_INDEX, beanId); } } private <F> F getValue(MethodInjectionPoint<T, X> injectionPoint, Field field, Class<F> targetClass) { return WildFlySecurityManager.doUnchecked(new PrivilegedAction<F>() { @Override public F run() { try { return targetClass.cast(TYPE_FIELD.get(injectionPoint)); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } } }); } }
6,281
44.521739
253
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/annotated/slim/AnnotatedParameterMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import java.io.IOException; import java.lang.reflect.Constructor; import jakarta.enterprise.inject.spi.AnnotatedCallable; import jakarta.enterprise.inject.spi.AnnotatedConstructor; import jakarta.enterprise.inject.spi.AnnotatedMethod; import jakarta.enterprise.inject.spi.AnnotatedParameter; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * Generic marshaller for an {@link AnnotatedParameter}. * @author Paul Ferraro */ public class AnnotatedParameterMarshaller<X, T extends SlimAnnotatedType<X>, C extends AnnotatedConstructor<X>, M extends AnnotatedMethod<X>, P extends AnnotatedParameter<X>> implements ProtoStreamMarshaller<P> { private static final int CONSTRUCTOR_INDEX = 1; private static final int METHOD_INDEX = 2; private static final int POSITION_INDEX = 3; private final Class<P> targetClass; private final Class<C> constructorClass; private final Class<M> methodClass; public AnnotatedParameterMarshaller(Class<P> targetClass, Class<C> constructorClass, Class<M> methodClass) { this.targetClass = targetClass; this.constructorClass = constructorClass; this.methodClass = methodClass; } @Override public Class<P> getJavaClass() { return this.targetClass; } @Override public P readFrom(ProtoStreamReader reader) throws IOException { AnnotatedCallable<X> callable = null; int position = 0; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case CONSTRUCTOR_INDEX: callable = reader.readObject(this.constructorClass); break; case METHOD_INDEX: callable = reader.readObject(this.methodClass); break; case POSITION_INDEX: position = reader.readUInt32(); break; default: reader.skipField(tag); } } return this.targetClass.cast(callable.getParameters().get(position)); } @Override public void writeTo(ProtoStreamWriter writer, P parameter) throws IOException { AnnotatedCallable<X> callable = parameter.getDeclaringCallable(); writer.writeObject(callable.getJavaMember() instanceof Constructor ? CONSTRUCTOR_INDEX : METHOD_INDEX, callable); int index = parameter.getPosition(); if (index > 0) { writer.writeUInt32(POSITION_INDEX, index); } }}
3,910
40.168421
212
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/annotated/slim/AnnotatedMethodMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import java.lang.reflect.Method; import jakarta.enterprise.inject.spi.AnnotatedMethod; import jakarta.enterprise.inject.spi.AnnotatedType; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.jboss.weld.util.reflection.DeclaredMemberIndexer; /** * Generic marshaller for an {@link AnnotatedMethod}. * @author Paul Ferraro */ public class AnnotatedMethodMarshaller<X, T extends SlimAnnotatedType<X>, M extends AnnotatedMethod<X>> extends AnnotatedCallableMarshaller<X, Method, T, AnnotatedMethod<? super X>, M> { public AnnotatedMethodMarshaller(Class<M> targetClass, Class<T> typeClass) { super(targetClass, typeClass, DeclaredMemberIndexer::getMethodForIndex, AnnotatedType::getMethods, DeclaredMemberIndexer::getIndexForMethod); } }
1,848
43.02381
186
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/annotated/slim/AnnotatedTypeIdentifierMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import java.io.IOException; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.Container; import org.jboss.weld.annotated.slim.AnnotatedTypeIdentifier; import org.jboss.weld.manager.BeanManagerImpl; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * Marshaller for an {@link AnnotatedTypeIdentifier}. * @author Paul Ferraro */ public class AnnotatedTypeIdentifierMarshaller implements ProtoStreamMarshaller<AnnotatedTypeIdentifier> { private static final int BEAN_MANAGER_INDEX = 1; private static final int CLASS_NAME_INDEX = 2; private static final int MODIFIED_CLASS_NAME_INDEX = 3; private static final int SUFFIX_INDEX = 4; @Override public Class<? extends AnnotatedTypeIdentifier> getJavaClass() { return AnnotatedTypeIdentifier.class; } @Override public AnnotatedTypeIdentifier readFrom(ProtoStreamReader reader) throws IOException { BeanManagerImpl manager = null; String className = null; boolean modified = false; String suffix = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case BEAN_MANAGER_INDEX: manager = reader.readAny(BeanManagerImpl.class); break; case MODIFIED_CLASS_NAME_INDEX: modified = true; case CLASS_NAME_INDEX: className = reader.readAny(String.class); break; case SUFFIX_INDEX: suffix = reader.readAny(String.class); break; default: reader.skipField(tag); } } return AnnotatedTypeIdentifier.of(manager.getContextId(), manager.getId(), className, suffix, modified); } @Override public void writeTo(ProtoStreamWriter writer, AnnotatedTypeIdentifier identifier) throws IOException { BeanManagerImpl manager = Container.instance(identifier.getContextId()).getBeanManager(identifier.getBdaId()); if (manager != null) { writer.writeAny(BEAN_MANAGER_INDEX, manager); } writer.writeAny(identifier.isModified() ? MODIFIED_CLASS_NAME_INDEX : CLASS_NAME_INDEX, identifier.getClassName()); String suffix = identifier.getSuffix(); if (suffix != null) { writer.writeAny(SUFFIX_INDEX, suffix); } } }
3,736
40.065934
123
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/annotated/slim/SlimAnnotatedMarshallerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshallerProvider; /** * @author Paul Ferraro */ public enum SlimAnnotatedMarshallerProvider implements ProtoStreamMarshallerProvider { IDENTIFIER(new AnnotatedTypeIdentifierMarshaller()), ; private final ProtoStreamMarshaller<?> marshaller; SlimAnnotatedMarshallerProvider(ProtoStreamMarshaller<?> marshaller) { this.marshaller = marshaller; } @Override public ProtoStreamMarshaller<?> getMarshaller() { return this.marshaller; } }
1,707
36.130435
86
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/annotated/slim/AnnotatedFieldMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import java.io.IOException; import java.lang.reflect.Field; import jakarta.enterprise.inject.spi.AnnotatedField; import jakarta.enterprise.inject.spi.AnnotatedType; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * Generic marshaller for an {@link AnnotatedField}. * @author Paul Ferraro */ public class AnnotatedFieldMarshaller<X, T extends SlimAnnotatedType<X>, F extends AnnotatedField<X>> implements ProtoStreamMarshaller<F> { private static final int TYPE_INDEX = 1; private static final int DECLARING_TYPE_INDEX = 2; private static final int FIELD_NAME_INDEX = 3; private final Class<F> targetClass; private final Class<T> typeClass; public AnnotatedFieldMarshaller(Class<F> targetClass, Class<T> typeClass) { this.targetClass = targetClass; this.typeClass = typeClass; } @Override public Class<F> getJavaClass() { return this.targetClass; } @Override public F readFrom(ProtoStreamReader reader) throws IOException { T type = null; Class<?> declaringType = null; String fieldName = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case TYPE_INDEX: type = reader.readObject(this.typeClass); break; case DECLARING_TYPE_INDEX: declaringType = reader.readObject(Class.class); break; case FIELD_NAME_INDEX: fieldName = reader.readString(); break; default: reader.skipField(tag); } } Class<?> fieldClass = (declaringType != null) ? declaringType : type.getJavaClass(); for (AnnotatedField<? super X> annotatedField : type.getFields()) { Field field = annotatedField.getJavaMember(); if ((field.getDeclaringClass() == fieldClass) && field.getName().equals(fieldName)) { return this.targetClass.cast(annotatedField); } } throw new IllegalStateException(); } @Override public void writeTo(ProtoStreamWriter writer, F field) throws IOException { AnnotatedType<X> type = field.getDeclaringType(); if (type != null) { writer.writeObject(TYPE_INDEX, type); } Field member = field.getJavaMember(); if (member != null) { Class<?> declaringClass = member.getDeclaringClass(); if (declaringClass != type.getJavaClass()) { writer.writeObject(DECLARING_TYPE_INDEX, declaringClass); } writer.writeString(FIELD_NAME_INDEX, member.getName()); } } }
4,143
38.466667
139
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/annotated/slim/AnnotatedConstructorMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import java.lang.reflect.Constructor; import jakarta.enterprise.inject.spi.AnnotatedConstructor; import jakarta.enterprise.inject.spi.AnnotatedType; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.jboss.weld.util.reflection.DeclaredMemberIndexer; /** * Generic marshaller for an {@link AnnotatedConstructor}. * @author Paul Ferraro */ public class AnnotatedConstructorMarshaller<X, T extends SlimAnnotatedType<X>, C extends AnnotatedConstructor<X>> extends AnnotatedCallableMarshaller<X, Constructor<X>, T, AnnotatedConstructor<X>, C> { public AnnotatedConstructorMarshaller(Class<C> targetClass, Class<T> typeClass) { super(targetClass, typeClass, DeclaredMemberIndexer::getConstructorForIndex, AnnotatedType::getConstructors, DeclaredMemberIndexer::getIndexForConstructor); } }
1,898
44.214286
201
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/annotated/slim/AnnotatedTypeMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import java.io.IOException; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.Container; import org.jboss.weld.annotated.slim.AnnotatedTypeIdentifier; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.resources.ClassTransformer; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * Generic marshaller for a {@link SlimAnnotatedType}. * @author Paul Ferraro */ public class AnnotatedTypeMarshaller<X, T extends SlimAnnotatedType<X>> implements ProtoStreamMarshaller<T> { private static final int IDENTIFIER_INDEX = 1; private final Class<T> targetClass; public AnnotatedTypeMarshaller(Class<T> targetClass) { this.targetClass = targetClass; } @Override public Class<? extends T> getJavaClass() { return this.targetClass; } @Override public T readFrom(ProtoStreamReader reader) throws IOException { AnnotatedTypeIdentifier identifier = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case IDENTIFIER_INDEX: identifier = reader.readObject(AnnotatedTypeIdentifier.class); break; default: reader.skipField(tag); } } BeanManagerImpl manager = Container.instance(identifier).getBeanManager(identifier.getBdaId()); return this.getAnnotatedType(identifier, manager); } @SuppressWarnings("unchecked") protected T getAnnotatedType(AnnotatedTypeIdentifier identifier, BeanManagerImpl manager) { return (T) ClassTransformer.instance(manager).getSlimAnnotatedTypeById(identifier); } @Override public void writeTo(ProtoStreamWriter writer, T type) throws IOException { AnnotatedTypeIdentifier identifier = type.getIdentifier(); if (identifier != null) { writer.writeObject(IDENTIFIER_INDEX, identifier); } } }
3,311
37.964706
109
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/annotated/slim/AnnotatedCallableMarshaller.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim; import java.io.IOException; import java.lang.reflect.Executable; import java.util.Set; import java.util.function.Function; import java.util.function.ToIntFunction; import jakarta.enterprise.inject.spi.AnnotatedCallable; import jakarta.enterprise.inject.spi.AnnotatedType; import org.infinispan.protostream.descriptors.WireType; import org.jboss.weld.annotated.slim.SlimAnnotatedType; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * Generic marshaller for an {@link AnnotatedCallable}. * @author Paul Ferraro */ public class AnnotatedCallableMarshaller<X, E extends Executable, T extends SlimAnnotatedType<X>, C extends AnnotatedCallable<? super X>, SC extends AnnotatedCallable<X>> implements ProtoStreamMarshaller<SC> { interface CallableLocator<X, E extends Executable> { E lookup(int position, Class<X> declaringClass); } private static final int TYPE_INDEX = 1; private static final int DECLARING_TYPE_INDEX = 2; private static final int POSITION_INDEX = 3; private final Class<SC> targetClass; private final Class<T> typeClass; private final CallableLocator<X, E> locator; private final Function<T, Set<C>> enumerator; private final ToIntFunction<E> indexer; public AnnotatedCallableMarshaller(Class<SC> targetClass, Class<T> typeClass, CallableLocator<X, E> locator, Function<T, Set<C>> enumerator, ToIntFunction<E> indexer) { this.targetClass = targetClass; this.typeClass = typeClass; this.locator = locator; this.enumerator = enumerator; this.indexer = indexer; } @Override public Class<? extends SC> getJavaClass() { return this.targetClass; } @Override public SC readFrom(ProtoStreamReader reader) throws IOException { T type = null; Class<X> declaringType = null; int position = 0; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case TYPE_INDEX: type = reader.readObject(this.typeClass); break; case DECLARING_TYPE_INDEX: declaringType = reader.readObject(Class.class); break; case POSITION_INDEX: position = reader.readUInt32(); break; default: reader.skipField(tag); } } E callable = this.locator.lookup(position, (declaringType != null) ? declaringType : type.getJavaClass()); for (AnnotatedCallable<? super X> annotatedCallable : this.enumerator.apply(type)) { if (annotatedCallable.getJavaMember().equals(callable)) { return this.targetClass.cast(annotatedCallable); } } throw new IllegalStateException(); } @Override public void writeTo(ProtoStreamWriter writer, SC callable) throws IOException { AnnotatedType<X> type = callable.getDeclaringType(); if (type != null) { writer.writeObject(TYPE_INDEX, type); } @SuppressWarnings("unchecked") E executable = (E) callable.getJavaMember(); if (executable != null) { Class<?> declaringType = executable.getDeclaringClass(); if (declaringType != type.getJavaClass()) { writer.writeObject(DECLARING_TYPE_INDEX, declaringType); } int position = this.indexer.applyAsInt(executable); if (position > 0) { writer.writeUInt32(POSITION_INDEX, position); } } } }
4,902
39.188525
209
java
null
wildfly-main/clustering/weld/core/src/main/java/org/wildfly/clustering/weld/annotated/slim/backed/BackedSlimAnnotatedMarshallerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.weld.annotated.slim.backed; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedConstructor; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedField; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedMethod; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedParameter; import org.jboss.weld.annotated.slim.backed.BackedAnnotatedType; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshallerProvider; import org.wildfly.clustering.weld.annotated.slim.AnnotatedConstructorMarshaller; import org.wildfly.clustering.weld.annotated.slim.AnnotatedFieldMarshaller; import org.wildfly.clustering.weld.annotated.slim.AnnotatedMethodMarshaller; import org.wildfly.clustering.weld.annotated.slim.AnnotatedParameterMarshaller; /** * @author Paul Ferraro */ public enum BackedSlimAnnotatedMarshallerProvider implements ProtoStreamMarshallerProvider { CONSTRUCTOR(new AnnotatedConstructorMarshaller<>(BackedAnnotatedConstructor.class, BackedAnnotatedType.class)), FIELD(new AnnotatedFieldMarshaller<>(BackedAnnotatedField.class, BackedAnnotatedType.class)), METHOD(new AnnotatedMethodMarshaller<>(BackedAnnotatedMethod.class, BackedAnnotatedType.class)), PARAMETER(new AnnotatedParameterMarshaller<>(BackedAnnotatedParameter.class, BackedAnnotatedConstructor.class, BackedAnnotatedMethod.class)), TYPE(new BackedAnnotatedTypeMarshaller<>()), ; private final ProtoStreamMarshaller<?> marshaller; BackedSlimAnnotatedMarshallerProvider(ProtoStreamMarshaller<?> marshaller) { this.marshaller = marshaller; } @Override public ProtoStreamMarshaller<?> getMarshaller() { return this.marshaller; } }
2,834
47.050847
145
java