On the premise that no API change would/will be allowed in the current
version, I've pursued experimentation and reached a solution.
Of course, if we were to change the API in 1.3, that makes what follows a
moot point.
So, let's assume we can only change the API in 1.4 after we deprecated in
1.3.
On passing the solrConfig; using a thread local to store a stack of
solrConfig, we are able to safely expose the intended instance to any of its
potential consumers.
We must use a stack since nothing prevents creating another core in the
middle of a FilterFactory initialization.
Which means calls to plugin constructors & initializations must made
exception safe to push/pop the solrConfig instance correctly.
Typical calls look like:
try {
solrConfig.tlsPush();
....
}
finally {
solrConfig.tlsPop();
}
This still leaves the other issue of how to state the future API at the time
we are deprecating one - and get rid of the current
SolrConfig.Initializable.
I've created a small package that exposes 2 annotations;
one is '@Future(version=...)' that allows to declare the future method
signature and another one - the opposite of @Deprecated
the other is '@Upward(version=...)' that allows a concrete instance to state
it already implements the new version (that would be before 1.4 in our
case).
As a small example, you state this in the API - assuming we are in 1.2:
public interface SomeFactory {
@Deprecated
public void init(String[] foo);
@Future(version=1.4)
interface future {
public void init(Map<String, String> arg);
}
}
And in the concrete class you do:
public class ConcreteFactory implements SomeFactory {
public void init(String[] foo) {
logger.info("calling deprecated version");
}
@Upward(version=1.4)
public void init(Map<String, String> arg) {
logger.info("calling new version");
}
...
>From a caller,you go through the package:
void SomeMemthod(SomeFactory f0) {
SomeFactory.future fx = Compatibility.cast(SomeFactory.future.class,
f0);
if (fx != null)
fx.init(null);
else
f0.init(null);
...
The bit of magic is in using some controlled Duck Typing to find the correct
method if it exists in the instance.
I'll try uploading the raw code for the Compatiblity package in case this
leaves you wondering.
So, how do we proceed now ?
How do we reach closure on the topic ?
--
View this message in context:
http://www.nabble.com/Initializing---break-init%28%29-API-compatibility--tf4808463.html#a13797406
Sent from the Solr - Dev mailing list archive at Nabble.com.