Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RATIS-1116. Add DataStreamType. (#238)
* RATIS-1116. Add DataStreamType. * Fix a bug and change the cast(..) method to newInstance(..).
- Loading branch information
Showing
11 changed files
with
153 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
ratis-client/src/main/java/org/apache/ratis/client/DisabledDataStreamClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.ratis.client; | ||
|
||
import org.apache.ratis.conf.Parameters; | ||
import org.apache.ratis.conf.RaftProperties; | ||
import org.apache.ratis.datastream.SupportedDataStreamType; | ||
import org.apache.ratis.protocol.RaftPeer; | ||
|
||
/** A stream factory that does nothing when data stream is disabled. */ | ||
public class DisabledDataStreamClientFactory implements DataStreamClientFactory { | ||
public DisabledDataStreamClientFactory(Parameters parameters) {} | ||
|
||
@Override | ||
public SupportedDataStreamType getDataStreamType() { | ||
return SupportedDataStreamType.DISABLED; | ||
} | ||
|
||
@Override | ||
public DataStreamClientRpc newDataStreamClientRpc(RaftPeer server, RaftProperties properties) { | ||
return new DataStreamClientRpc() { | ||
@Override | ||
public void startClient() {} | ||
|
||
@Override | ||
public void closeClient() {} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
ratis-common/src/main/java/org/apache/ratis/datastream/DataStreamType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.ratis.datastream; | ||
|
||
import org.apache.ratis.conf.Parameters; | ||
import org.apache.ratis.util.ReflectionUtils; | ||
|
||
/** The type of data stream implementations. */ | ||
public interface DataStreamType { | ||
/** | ||
* Parse the given string as a {@link SupportedDataStreamType} | ||
* or a user-defined {@link DataStreamType}. | ||
* | ||
* @param dataStreamType The string representation of an {@link DataStreamType}. | ||
* @return a {@link SupportedDataStreamType} or a user-defined {@link DataStreamType}. | ||
*/ | ||
static DataStreamType valueOf(String dataStreamType) { | ||
final Throwable fromSupportedRpcType; | ||
try { // Try parsing it as a SupportedRpcType | ||
return SupportedDataStreamType.valueOfIgnoreCase(dataStreamType); | ||
} catch (Throwable t) { | ||
fromSupportedRpcType = t; | ||
} | ||
|
||
try { | ||
// Try using it as a class name | ||
return ReflectionUtils.newInstance(ReflectionUtils.getClass(dataStreamType, DataStreamType.class)); | ||
} catch(Throwable t) { | ||
final IllegalArgumentException iae = new IllegalArgumentException( | ||
"Invalid " + DataStreamType.class.getSimpleName() + ": \"" + dataStreamType + "\" " | ||
+ " cannot be used as a user-defined " + DataStreamType.class.getSimpleName() | ||
+ " and it is not a " + SupportedDataStreamType.class.getSimpleName() + "."); | ||
iae.addSuppressed(t); | ||
iae.addSuppressed(fromSupportedRpcType); | ||
throw iae; | ||
} | ||
} | ||
|
||
/** @return the name of the rpc type. */ | ||
String name(); | ||
|
||
/** @return a new client factory created using the given parameters. */ | ||
DataStreamFactory newClientFactory(Parameters parameters); | ||
|
||
/** @return a new server factory created using the given parameters. */ | ||
DataStreamFactory newServerFactory(Parameters parameters); | ||
|
||
/** An interface to get {@link DataStreamType}. */ | ||
interface Get { | ||
/** @return the {@link DataStreamType}. */ | ||
DataStreamType getDataStreamType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters