3

I am using the MPJ-api for my current project. The two implementations I am using are MPJ-express and Fast-MPJ. However, since they both implement the same API, namely the MPJ-API, I cannot simultaneously support both implementations due to name-space collisions.

Is there any way to wrap two different libraries with the same package and class-names such that both can be supported at the same time in Java or Scala?

So far, the only way I can think of is to move the module into separate projects, but I am not sure this would be the way to go.

Cactus
  • 27,075
  • 9
  • 69
  • 149
Felix
  • 8,385
  • 10
  • 40
  • 59

1 Answers1

0

If your code use only a subset of MPI functions (like most of the MPI code I've reviewed), you can write an abstraction layer (traits or even Cake-Pattern) which defines the ops your are actually using. You can then implement a concrete adapter for each implementation.

This approach will also work with non-MPI communication layers (think Akka, JGroups, etc.)

As a bonus point, you could use the SLF4J approach: the correct implementation is chosen at runtime according to what's actually in the classpath.

paradigmatic
  • 40,153
  • 18
  • 88
  • 147
  • I don't think this is gonna work since both jars I need to add contain a class called mpi.MPI. This wouldn't be a problem because I could hot-swap the jar files, but there are even inconsistencies in the libraries where some methods are (wrongly) capitalized... – Felix Nov 13 '12 at 17:20
  • @Felix Good point. You can use `JarJar` to rename the packages: http://radomirml.com/2009/11/08/repackaging-conflicting-jars-with-jarjar I must confess I never tried it. – paradigmatic Nov 13 '12 at 17:26