Click here to Skip to main content
15,883,731 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi
So finally my Java smart card Utility
CSS
(See my previous questions) 
is developed n working in fully fledged way. But Now the new work is on
CSS
Memcache

I have to implement memcache service in java for MS SQL server 2008 for Databases of high latency n redundancy n low availability.

Any thoughts on how to start the activity are most welcome. Please provide some hint n ideas about memcache service to be implemented in java.


Thanks a lot Guys for your support in my first activity .

Thanks & Regards,
Anil Kumar
Posted

1 solution

Do you have a facade[^] in your aplication?

if so it's simple, you would only have to extend the write/read and delete mechanisms.

How to implement a facade into an existing application:
- set up a class "FacadeService". that one is triggered BEFORE your GUI starts.
- FacadeService implements Serializable. the class needs a methode "getInstance()" which gives back a instance of FacadeService.
This is your general entrance point. FacadeService pulls up the rest of the facade (in this example a facade to store Customers in):

Java
import java.io.Serializable;

public class FacadeService implements Serializable {
	private static final long serialVersionUID = 1L;

	private static final FacadeService oFacadeService = new FacadeService();
	
	private final CustomerFacade oCustomerFacade = new CustomerFacade();
	
	public FacadeService(){
		// maybe do something or just leave unfunctional
	}
	
	public static FacadeService getInstance(){
		return oFacadeService;
		
	}
	
	public CustomerFacade getCustomerFacade(){
		return oCustomerFacade;
	}
}


Java
import java.io.Serializable;

public class CustomerFacade implements Serializable {
	private static final long serialVersionUID = 1L;

	private final CustomerFacade oCustomerFacade = new CustomerFacade();
	
	public CustomerFacade(){
		this.ignition();
	}
	
	private void ignition() {
		// load data at startup from DB
	}

	public CustomerFacade getInstance(){
		return oCustomerFacade;
	}
}


- now your complete GUI should read from this facade:

Java
private CustomerFacade getCustomerFacade(){
  return FacadeService.getInstance().getCustomerFacade();
}


- Make sure you can store everything at runtime. Create objects that dublicate each object in the database.
- make sure you are reading the DB at startup to fill your facade.
- make sure you are writing to the DB each time a value changes. You can set up for that general methods that help you. Even a class "DatabaseConnector" would be helpful to gather all the read/write/modify methods. make sure the DB actions are made asynchronous (Threading[^]) so they do not block your application.
- make sure your GUI is not reading from the DB aside of the facade. Your application should be able to run without the DB/just from the Facade data (the facade is empty if the database could not be read).

NOTE:
I know that this is not the intended use of Serializable and the design is not general applicable. But it's a simple, easy to implement approach to add a facade to an existing application.
 
Share this answer
 
Comments
Anil Kumar 23 8-Jun-12 6:59am    
Hi Torsten,
Initially do i need any extra server to connect to rum memcache java code... as i have seen after googling few memcache servers.
Will my normal ofice server be able to do memcache service??? I have seen few articles but nothing really clicks to have a proper plan to implement java with memcache service.. Can u provide some links or some workflow of process from installing server configuration to running a simple hello world program in memcache...
TorstenH. 8-Jun-12 14:11pm    
You are talking about a server sided "memcache" - I'm talking about a client with a runtime persistence to minimize/prevent server requests.

So totally other approach.

A server sided memcache does not make sense, cause one has still the server requests - without direct SQL Action, but still a server request with a lot of performance costs.
It's much more effective when the client is able to hold the data itself and only talks to the sever when needed. The talking can be done in a none GUI thread, which makes the client fast and sweet to use.
Anil Kumar 23 10-Jun-12 3:22am    
Hey Torsten,
See what i am trying to do is to write a code in java to demonstrate the distributed memory caching system "memcache". For that i m trying to gather resources and knowledge. Can you suggest any particular approach for dat... or ny suggestions for how to go through with the code.
I understood your solution on facade but not actually able to understand how to implement that with distributing memory caching.
TorstenH. 10-Jun-12 3:37am    
hmm, does it make much sense to cache on server side? however.

Google has something for that in their Google App API
WIkipedia offers also a lot of Infos on Memcached, but that is also client sided.

and here: is a Blog on a pretty big approach on using memcached Clickedy

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900