Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to use hashmap to check updated files to transfer from client to server  RSS feed

 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi masters

can anyone give me some examples to show how the hashmap to check updated files and then send it to server side? I have two folders, one is input folder which means client side, other is output folder which means the server side. Thus my task is to check my input got any new files or modified files, if yes, transfer; If not, do not need to transfer.
1) I want to use hashmap to check the modified files or new files, but I am not too sure that where I should put hashmap method, is it at client side?
2) is map.put() and map.get() enough for my request?
3) I tried to use map.put() and map.get() to my client side, but it doesn't work. I feel that with or without hashmap method, my files just transfer from client to server.
4) Can anyone give me a hint how to use hashmap in client and server socket program, or should I use hashmap for both client and server side? If yes, how to do? any examples can show me?

Thanks very much, appreciate your guys help! any help will be good.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shen,
Back after a while to Java Ranch...

Just taking a shot here..

May be you could use Apache Camel here?

check for an example here..
you'll need to dig a little to find how to do a remote transfer..

apache camel site
 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gamini
Thanks for the reply, however I have to use this hashmap method to do a demonstration. thanks, any question you could answer, will be good!
 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

anyone can help me a bit?

Thanks very much in advance
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you are unsure of how to use a HashMap for this, start by telling us *why* you decided to use it. That's an implementation decision which should be made after you have decided the overall approach (and to me at least it's not immediately clear how that particular class would help). So start by telling us what the overall algorithm will be.
 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply, sorry I was not clear, this project I am doing requiring me to use hashmap method to get modified files and transfer to server side the file when the client has new modified files. what I don't understand when I try to write the code is, let's see if I want to retrieve previous last modified date, how do I do ? explam: long A = previoius time from file1; long B= current modified time from file2; if B>A, file starts to transfer, if not, do not transfer. what i don't get it file.lastmodified() is to get files' current modified date. how about if i want previous modified time, that means before the current modified date. how do i do it? thanks very much, i know my question is a bit long. Please let me know if you don't understand me, thanks
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That really doesn't explain *why* you want (or need to) use a HashMap.
 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:That really doesn't explain *why* you want (or need to) use a HashMap.

hi Ulf Dittmer

it's one of the requirements. I hope you can understand it's part of requirement. thanks
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shen zhang wrote:this project I am doing requiring me to use hashmap method to get modified files and transfer to server side the file when the client has new modified files

Hashmaps are used for storing Objects. There is no Hashmap method to get modified files and transfer to server side. You can write code to retrieve file details and store those details in a HashMap, but the HashMap itself can't do that for you. Nor can it transfer files
shen zhang wrote:if I want to retrieve previous last modified date, how do I do ? explam: long A = previoius time from file1; long B= current modified time from file2; if B>A, file starts to transfer, if not, do not transfer. what i don't get it file.lastmodified() is to get files' current modified date. how about if i want previous modified time

Not many (if any) file systems store that sort of information. You need to get that date when it is the last modified time and store it somewhere. Without knowing more details of your design and requirements it is difficult to recommend where you store it.
 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joanne
Thanks for the reply. yes, maybe I put up my code, it will be easier for you.

what I feel is that, long A and long B, actually the same. but what I want to long A to be previous modified date, long B is current modified date, I do not know how to set for long A, thanks for your help
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If that's your actual code, it would seem unlikely that the file's last modified time has actually changed. You put the File object and time into the HashMap (at line 3) and then immediately retrieve it (at line 21). There are probably only microseconds (if not less) between those instructions, so it's extremely unlikely the last modified time has changed.
 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Joanne

Thanks for reply, does it mean I need to retrieve it in another loop? how does it work? could you give an example? thanks very much
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That really doesn't explain *why* you want (or need to) use a HashMap.

it's one of the requirements. I hope you can understand it's part of requirement.

Actually, I don't. It can't be part of the overall requirements, because the use of data structures (or even actual programming language classes) is an implementation decision - those have no place in the general requirements, because they're decided by the developer (you in this case). If there are some technical requirements that you haven't told us about which make the use of this class necessary, I advise to talk to whoever came up with that requirement, because it sounds as if you don't know why it exists - and you can't implement something you don't understand.
 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf
I post my code, not sure if that will be good for you to understand me. unfortunately, no one is making a requirement, only write in the paper. I just want to use hashmap to store the old file and retrieve old file.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shen zhang wrote:does it mean I need to retrieve it in another loop?

You definitely need to retrieve it somewhere else in your program - whether that's in a loop or not depends on your requirements and design.
shen zhang wrote:how does it work? could you give an example? thanks very much

How does what work ? The way you are adding and retrieving values to/from your HashMap is correct. The problem is the design of your program.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
unfortunately, no one is making a requirement, only write in the paper.

So someone *is* making that a requirement - it doesn't matter how it gets conveyed to you. My advice is to get clarification on all requirements that you don't fully understand, and that includes that reason why that requirement exists. And what's more, technical requirements that come from non-technical sources (project managers, clients, etc.) generally should be challenged and possibly scratched. If you don't feel senior enough to do that, have your manager do it for you - he should shield you from unreasonable requirements.
 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
shen zhang wrote:does it mean I need to retrieve it in another loop?

You definitely need to retrieve it somewhere else in your program - whether that's in a loop or not depends on your requirements and design.
shen zhang wrote:how does it work? could you give an example? thanks very much

How does what work ? The way you are adding and retrieving values to/from your HashMap is correct. The problem is the design of your program.

hi
This is what I found out,
new file:
put the last modified time to the map
send to server
Existing file:
long A= get the last modified time from the map
long B= get the current modified time of the file
if (B>A), means file is modified, put the new B back into the map and send this file to server.
I feel my code shown is following the logical for existing file, please tell me, am I wrong? I need to retrieve the value somewhere else? Can retrieve value to server side? the code I showed to you is client side.
 
shen zhang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
shen zhang wrote:does it mean I need to retrieve it in another loop?

You definitely need to retrieve it somewhere else in your program - whether that's in a loop or not depends on your requirements and design.
shen zhang wrote:how does it work? could you give an example? thanks very much

How does what work ? The way you are adding and retrieving values to/from your HashMap is correct. The problem is the design of your program.

hi Joanne

I think I know where is my problem, where to put "hashmap= new hashmap()" is also important. I think that is what you mean by retrieve it somewhere, am I right?

Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!