0

I'm developing an application using JAVA EE 6, more specifically, Glassfish v3.1.2.2.

Before, I used to put images and files uploded by users in my database. this would make it easier in case I ever wanted to clusterize my architecture by adding nodes.

Now, I'd really like to stop doing that and just save my uploaded files to my resources folder (for many reasons such as this), so that a simple <img> or <h:graphicImage> with a name will do the trick.

My question is how does this work when I add other servers? The file will only be saved to the server's resources folder that handles the request, the other servers won't have it.

Now maybe someone would suggest using a distributed filesystem, which sounds great except in cases where you are renting some hosting/cloud service for your app and you can't really choose your filesystem. (There could be other reasons that prevent you from turning to this setting)

Does JAVA EE offer any way of transparently synchronizing your resources folder? JSF already handles versioning of it and managing libraries etc, any chance I can set up some configuration so all my servers keep their resource folders up to date with any file changes/uploads?

If not, what are the alternatives?

Community
  • 1
  • 1
arg20
  • 4,893
  • 1
  • 50
  • 74
  • I have not worked with clusters myself, but from what I read probably the best option is to set static resources in a dedicated server (typically an apache because it is considered faster) – SJuan76 Mar 09 '13 at 23:35
  • Do you have an example of a cloud service that lets you run a cluster of your application but doesn't have any way of actually communicating between the nodes? This sounds like a somewhat arbitrary restriction. (Also, I think a popular - if possibly needlessly pricey - solution is to just punt these to S3 or some other sort of CDN, which should provide some sort of API to upload new files.) – millimoose Mar 09 '13 at 23:55
  • As millimoose states, I would also opt for a [Content Delivery Network](http://en.wikipedia.org/wiki/Content_delivery_network) solution like Amazon S3 (disclaimer: I do not work nor related with Amazon on any way). – Luiggi Mendoza Mar 10 '13 at 00:36
  • Isn't it strange though that the JAVA EE platform does not support this out of the box? Am I missing something here? Maybe I'm just not seeing clearly the way I should do things. Maybe a third party extension or non-standarised solution? Something from Jboss or any other vendor? – arg20 Mar 10 '13 at 04:49

1 Answers1

0

Java EE doesn't offer a way to synchronize your images in a common folder for clusters , your appserver may support something for this but I am not aware of any such solutions in appserver.

Based on your situation I would use a NFS server and keep the files on the NFS server directories accessible from all the clusters.

If you are not allowed to change your hardware setup then you can create a web server to host the resources and you can access your resources from all the clusters like,

<h:graphicImage value="http://myimageserver.local.com/sitename/foldername/xyz.gif"/> on all your clusters.

Avinash Singh
  • 3,421
  • 2
  • 20
  • 21
  • 1
    How are you going to do that when the nodes of the cluster are running on separate machines (as is the standard use case) without using some form of distributed file system OP's not inclined to use? – fvu Mar 09 '13 at 23:45
  • If my nodes are running on different machines or even virtualized environments, I cannot create symbolic links. – arg20 Mar 09 '13 at 23:47
  • I had somehow missed on your post that you are not using a dsitributed system or NFS . I guess the resource server is your option in that case. – Avinash Singh Mar 09 '13 at 23:51
  • @fvu If you're running a system that requires multiple heterogenous nodes, you'll face more complicated problems that this. You could always just write a custom service that will run on the static media node to deposit file uploads. – millimoose Mar 09 '13 at 23:56
  • @arg20 I'm not sure symbolic links have much to do with this. The idea is that these files would live on an entirely different "kind" of server/node than your application does, and your application would link to what is, from its point of view, a different server entirely, not to its own resources. – millimoose Mar 09 '13 at 23:59