1

What are the consequences (or issues that I might face) if I try to hack Xodus File I/O, as such I will use ByteBuddy to replace all access to Java File I/O and that Xodus will actually "persist" to that interface instead of the disk I/O, since I find it inefficient (and almost impossible) to have persistent storage on cloud platforms (Heroku, Openshift to names a few)--so this hack I am thinking is to create my own Java File I/O that instead of saving to disk it will save to a more elastic storage, such as Google Cloud Storage, S3 and other Object storage. So that I can run my app in Heroku or Openshift.

Will there be a side-effect with Xodus if I replace the File I/O with ByteBuddy or Xodus database is agnostic about it?

Questionaut
  • 89
  • 1
  • 6

1 Answers1

2

For a cleaner approach, you should refactor to using the NIO2 FileSystem abstraction and then use the file system you intended to use. At the same time, I understand that this is not always possible.

If you wanted to replace the File API, the simplest way would probably be to redefine the File class to implement operations in the way you wanted to. Have a look at the AgentBuilder API for this and use RedefinitionStrategy.RETRANSFORM.

When redefining the File class, you can use Advice which inlines the code of templates and also allows you to override implementations. In this case, you can use Advice as an interceptor:

builder = builder.method(...).intercept(Advice.to(MyAdvice.class));

where you control the implementation, typically from an exit advice where you can set return values as follows:

class MyAdvice {
  @Advice.OnMethodExit
  void exit(@Advice.Return(readOnly = false) Void value) {
    value = ...;
  }
}

If you want to leave parts of the File API intact, you can also use advice as decorator:

builder = builder.visit(Advice.to(MyAdvice.class).on(...));

where you can determine if the original method should be executed from an enter method.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
  • When you replace the File API for example does it replace across the whole application lifecycle? For example for a web application does it replace every call (e.g. calls from other libraries that may need to actually write to file for boostrapping etc.) or just for specific packages? – quarks Apr 28 '20 at 13:21
  • It rewrites the code as if you actually programmed it that way. What classes it affects depends on how you set up the `type` step matcher and the `ignore` statement. – Rafael Winterhalter Apr 28 '20 at 16:29