Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
MODULE: ServiceLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-at-work authored and albertogpz committed Feb 4, 2022
1 parent 0be467b commit 07884e8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
# agreements. See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the License. You may obtain a
# copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#

org.apache.geode.cache.wan.internal.txgrouping.serial.TxGroupingSerialGatewaySenderTypeFactory
org.apache.geode.cache.wan.internal.txgrouping.parallel.TxGroupingParallelGatewaySenderTypeFactory
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package org.apache.geode.cache.wan.internal;

import static java.lang.String.format;
import static java.util.ServiceLoader.load;
import static java.util.stream.StreamSupport.stream;

import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -29,8 +31,6 @@
import org.apache.geode.cache.wan.GatewaySender.OrderPolicy;
import org.apache.geode.cache.wan.GatewaySenderFactory;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.apache.geode.cache.wan.internal.parallel.ParallelGatewaySenderTypeFactory;
import org.apache.geode.cache.wan.internal.serial.SerialGatewaySenderTypeFactory;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.wan.GatewaySenderAttributes;
Expand Down Expand Up @@ -232,27 +232,26 @@ public GatewaySenderFactory setEnforceThreadsConnectSameReceiver(
final @NotNull GatewaySenderAttributes attributes) {
if (attributes.isParallel()) {
if (attributes.mustGroupTransactionEvents()) {
return findGatewaySenderTypeFactory(
"org.apache.geode.cache.wan.internal.txgrouping.parallel.TxGroupingParallelGatewaySenderTypeFactory");
return findGatewaySenderTypeFactory("TxGroupingParallelGatewaySender");
} else {
return new ParallelGatewaySenderTypeFactory();
return findGatewaySenderTypeFactory("ParallelGatewaySender");
}
} else {
if (attributes.mustGroupTransactionEvents()) {
return findGatewaySenderTypeFactory(
"org.apache.geode.cache.wan.internal.txgrouping.serial.TxGroupingSerialGatewaySenderTypeFactory");
return findGatewaySenderTypeFactory("TxGroupingSerialGatewaySender");
} else {
return new SerialGatewaySenderTypeFactory();
return findGatewaySenderTypeFactory("SerialGatewaySender");
}
}
}

private static GatewaySenderTypeFactory findGatewaySenderTypeFactory(final @NotNull String name) {
try {
return (GatewaySenderTypeFactory) Class.forName(name).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new GatewaySenderException(format("Can't find GatewaySender factory for %s.", name), e);
}
private static @NotNull GatewaySenderTypeFactory findGatewaySenderTypeFactory(
final @NotNull String name) {
return stream(load(GatewaySenderTypeFactory.class).spliterator(), false)
.filter(factory -> factory.getType().equals(name)
|| factory.getClass().getName().startsWith(name))
.findFirst()
.orElseThrow(() -> new GatewaySenderException("No factory found for " + name));
}

static void validate(final @NotNull InternalCache cache,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
# agreements. See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the License. You may obtain a
# copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#

org.apache.geode.cache.wan.internal.serial.SerialGatewaySenderTypeFactory
org.apache.geode.cache.wan.internal.parallel.ParallelGatewaySenderTypeFactory

0 comments on commit 07884e8

Please sign in to comment.