4c4
<  * Copyright (c) 2004-2010, Sun Microsystems, Inc., All Rights Reserved
---
>  * Copyright (c) 2004-2009, Sun Microsystems, Inc., All Rights Reserved
28d27
< import java.text.MessageFormat;
34c33,37
< import java.util.ResourceBundle;
---
> import java.util.concurrent.Callable;
> import java.util.concurrent.ExecutionException;
> import java.util.concurrent.ExecutorService;
> import java.util.concurrent.Executors;
> import java.util.concurrent.Future;
72,76c75
<     private static final Logger LOGGER = Logger.getLogger(
<             MultimeshEvolverAvatarConfigManager.class.getName());
<     private static final ResourceBundle BUNDLE = ResourceBundle.getBundle(
<             "org/jdesktop/wonderland/modules/evolvermulti/client/evolver/"
<             + "resources/Bundle");
---
>     private static final Logger logger = Logger.getLogger(MultimeshEvolverAvatarConfigManager.class.getName());
103c102
<             LOGGER.info("Using local Evolver avatar collection " +
---
>             logger.info("Using local Evolver avatar collection " +
106c105
<             LOGGER.log(Level.WARNING, "Unable to fetch evolver/ collection", excp);
---
>             logger.log(Level.WARNING, "Unable to fetch evolver/ collection", excp);
124c123
<             LOGGER.log(Level.WARNING, "Unable to fetch local avatars from " +
---
>             logger.log(Level.WARNING, "Unable to fetch local avatars from " +
162a162,163
> 
>         try {
163a165,168
>         } catch (ExecutionException ee) {
>             logger.log(Level.WARNING, "Error syncing avatar", ee);
>             return null;
>     }
195c200
<             LOGGER.info("Adding server " + session.getServerURL());
---
>             logger.info("Adding server " + session.getServerURL());
201c206
<                     LOGGER.info("Server " + session.getServerURL() +
---
>                     logger.info("Server " + session.getServerURL() +
212c217
<                 LOGGER.info("Starting sychronization with server " +
---
>                 logger.info("Starting sychronization with server " +
218c223
<                 LOGGER.info("Sychronization with server " +
---
>                 logger.info("Sychronization with server " +
221c226
<                 LOGGER.log(Level.WARNING, "Unable to create sync thread for " +
---
>                 logger.log(Level.WARNING, "Unable to create sync thread for " +
223a229,232
>             } catch (ExecutionException ee) {
>                 logger.log(Level.WARNING, "Unable to create sync thread for " +
>                         "server " + session.getServerURL(), ee);
>                 return;
230c239
<                 LOGGER.info("Added server " + session.getServerURL() +
---
>                 logger.info("Added server " + session.getServerURL() +
285c294
<                             LOGGER.log(Level.WARNING, "Attempt to delete the" +
---
>                             logger.log(Level.WARNING, "Attempt to delete the" +
289c298,303
<                         }
---
>                        } catch (ExecutionException ee) {
>                             logger.log(Level.WARNING, "Attempt to delete the" +
>                                     " avatar " + avatar.getName() + " from " +
>                                     "the server " + c.toString() + " threw " +
>                                     ee, ee);
>                          }
293c307
<                 LOGGER.log(Level.WARNING, "Unable to remove avatar", excp);
---
>                 logger.log(Level.WARNING, "Unable to remove avatar", excp);
313c327
<         LOGGER.info("Creating avatar with name " + avatarName);
---
>         logger.info("Creating avatar with name " + avatarName);
320,323c334,337
<             String message = BUNDLE.getString("Replace_Avatar_Message");
<             message = MessageFormat.format(message, avatarName);
<             int result = JOptionPane.showConfirmDialog(frame, message,
<                     BUNDLE.getString("Replace_Avatar_Title"),
---
>             int result = JOptionPane.showConfirmDialog(frame,
>                     "The avatar " + avatarName + " already exists in the " +
>                     "content repository. Do you wish to replace it and " +
>                     "continue?", "Replace avatar?",
338c352
<                 LOGGER.info("Deleting exsiting avatar locally with " +
---
>                 logger.info("Deleting exsiting avatar locally with " +
342c356
<                 LOGGER.log(Level.WARNING, "Unable to remove local avatar " +
---
>                 logger.log(Level.WARNING, "Unable to remove local avatar " +
352c366
<                 LOGGER.info("Deleting existing avatar directory locally" +
---
>                 logger.info("Deleting existing avatar directory locally" +
357c371
<                     LOGGER.log(Level.WARNING, "Unable to remove local avatar " +
---
>                     logger.log(Level.WARNING, "Unable to remove local avatar " +
362c376
<                 LOGGER.info("Did not find evolver avatar directory locally" +
---
>                 logger.info("Did not find evolver avatar directory locally" +
371c385
<             LOGGER.info("Attempting to delete avatar to server, number=" +
---
>             logger.info("Attempting to delete avatar to server, number=" +
380c394
<                         LOGGER.info("Schedule delete of existing avatar " +
---
>                         logger.info("Schedule delete of existing avatar " +
385c399
<                         LOGGER.log(Level.WARNING, "Attempt to delete the" +
---
>                         logger.log(Level.WARNING, "Attempt to delete the" +
388a403,407
>                     } catch (ExecutionException ee) {
>                         logger.log(Level.WARNING, "Attempt to delete the" +
>                                 " avatar " + avatarName + " from " +
>                                 "the server " + t.toString() + " threw " +
>                                 ee, ee);
394c413
<         LOGGER.info("Uploading avatar name " + avatarName + " to user's" +
---
>         logger.info("Uploading avatar name " + avatarName + " to user's" +
405c424
<             LOGGER.info("Already have an avatar named " + avatarName +
---
>             logger.info("Already have an avatar named " + avatarName +
420,423c439,441
<                     BUNDLE.getString("Avatar_Upload_Failed"),
<                     BUNDLE.getString("Upload_Failed"),
<                     JOptionPane.ERROR_MESSAGE);
<             LOGGER.log(Level.WARNING, "Failed to upload avatar to local user" +
---
>                     "Failed to upload the avatar. Please see the log files " +
>                     "for more details.", "Upload Failed", JOptionPane.ERROR_MESSAGE);
>             logger.log(Level.WARNING, "Failed to upload avatar to local user" +
435c453
<         LOGGER.warning("Using local repo base URL of " + localRepoBaseURL);
---
>         logger.warning("Using local repo base URL of " + localRepoBaseURL);
447c465
<             LOGGER.warning("ATTR: " + ce.toString());
---
>             logger.warning("ATTR: " + ce.toString());
467c485
<             LOGGER.info("Writing avatar to resource " + file.getPath());
---
>             logger.info("Writing avatar to resource " + file.getPath());
478c496
<             LOGGER.log(Level.WARNING, "Unable to write avatar configuration" +
---
>             logger.log(Level.WARNING, "Unable to write avatar configuration" +
490c508
<             LOGGER.info("Put avatar named " + avatarName + " in list of avatars");
---
>             logger.info("Put avatar named " + avatarName + " in list of avatars");
496c514
<             LOGGER.info("Attempting to upload avatar to server, number=" +
---
>             logger.info("Attempting to upload avatar to server, number=" +
503c521
<                     LOGGER.info("Schedule upload of avatar named " + avatarName +
---
>                     logger.info("Schedule upload of avatar named " + avatarName +
507c525
<                     LOGGER.log(Level.WARNING, "Attempt to upload the avatar " +
---
>                     logger.log(Level.WARNING, "Attempt to upload the avatar " +
509a528,531
>                 } catch (ExecutionException ee) {
>                     logger.log(Level.WARNING, "Attempt to upload the avatar " +
>                             avatar.getName() + " to the server " + t.toString() +
>                             " threw " + ee, ee);
516c538
<             LOGGER.info("Registering avater named " + avatarName + " in the system");
---
>             logger.info("Registering avater named " + avatarName + " in the system");
567c589
<             LOGGER.log(Level.WARNING, "Unable to create content directory for" +
---
>             logger.log(Level.WARNING, "Unable to create content directory for" +
584c606
<             LOGGER.log(Level.WARNING, null, ex);
---
>             logger.log(Level.WARNING, null, ex);
586c608
<             LOGGER.log(Level.WARNING, null, ex);
---
>             logger.log(Level.WARNING, null, ex);
603c625
<             LOGGER.log(Level.WARNING, "Unable to create file for " +
---
>             logger.log(Level.WARNING, "Unable to create file for " +
618c640
<             LOGGER.log(Level.WARNING, "Unable to write content from " + fileName +
---
>             logger.log(Level.WARNING, "Unable to write content from " + fileName +
661c683
<     private class ServerSyncThread extends Thread {
---
>     private class ServerSyncThread {
664,667c686
<         private ServerSessionManager manager = null;
< 
<         // A queue of jobs to execute on the thread.
<         private LinkedBlockingQueue<Job> jobQueue = new LinkedBlockingQueue();
---
>         private final ServerSessionManager manager;
670c689
<         private ContentCollection serverCollection = null;
---
>         private final ContentCollection serverCollection;
674c693
<         private Map<String, EvolverServerAvatar> serverAvatars = new HashMap();
---
>         private final Map<String, EvolverServerAvatar> serverAvatars = new HashMap();
675a695,698
>         // an executor to execute the tasks
>         private final ExecutorService executor =
>                 Executors.newSingleThreadExecutor();
> 
681,682d703
< 
<             super(ThreadManager.getThreadGroup(), "AvatarServerSyncThread");
688,690d708
< 
<             // Finally, start the thread off
<             this.start();
701c719,722
<             this.isConnected = isConnected;
---
>             System.out.println("******************* set isConnected to " + isConnected);
>             if(isConnected) {
>                 executor.shutdownNow();
>             }
712,716c733,743
<         public URL getAvatarServerURL(MultimeshEvolverAvatar avatar) throws InterruptedException {
<             Job job = Job.newGetURLJob(avatar);
<             jobQueue.add(job);
<             job.waitForJob();
<             return job.url;
---
>         public URL getAvatarServerURL(final MultimeshEvolverAvatar avatar)
>                 throws InterruptedException, ExecutionException
>         {
>             Callable<URL> job = new Callable<URL>() {
>                 public URL call() throws Exception {
>                     return getURLImpl(avatar);
>         }
>             };
> 
>             Future<URL> f = executor.submit(job);
>             return f.get();
727,729c754,763
<         public void scheduleSync(boolean isWait) throws InterruptedException {
<             Job job = Job.newSyncJob();
<             jobQueue.add(job);
---
>         public void scheduleSync(boolean isWait)
>                 throws InterruptedException, ExecutionException
>         {
>             Runnable job = new Runnable() {
>                 public void run() {
>                     syncImpl();
>                 }
>             };
> 
>             Future f = executor.submit(job);
731c765
<                 job.waitForJob();
---
>                 f.get();
734a769
> 
743,745c778,787
<         public void scheduleDelete(MultimeshEvolverAvatar avatar, boolean isWait) throws InterruptedException {
<             Job job = Job.newDeleteJob(avatar);
<             jobQueue.add(job);
---
>         public void scheduleDelete(final MultimeshEvolverAvatar avatar, boolean isWait)
>                 throws InterruptedException, ExecutionException
>         {
>             Runnable job = new Runnable() {
>                 public void run() {
>                     deleteImpl(avatar);
>                 }
>             };
> 
>             Future f = executor.submit(job);
747c789
<                 job.waitForJob();
---
>                 f.get();
759,761c801,810
<         public void scheduleUpload(MultimeshEvolverAvatar avatar, boolean isWait) throws InterruptedException {
<             Job job = Job.newUploadJob(avatar);
<             jobQueue.add(job);
---
>         public void scheduleUpload(final MultimeshEvolverAvatar avatar, boolean isWait)
>                 throws InterruptedException, ExecutionException
>         {
>             Runnable job = new Runnable() {
>                 public void run() {
>                     uploadFilesImpl(avatar);
>                 }
>             };
> 
>             Future f = executor.submit(job);
763c812
<                 job.waitForJob();
---
>                 f.get();
787,824d835
<          * {@inheritDoc}
<          */
<         @Override
<         public void run() {
<             while (isConnected == true) {
<                 // Fetch the next job. If we are interrupted in doing so, then
<                 // simply log an error and continue.
<                 Job job = null;
<                 try {
<                     job = jobQueue.take();
<                 } catch (InterruptedException excp) {
<                     LOGGER.log(Level.WARNING, "Attempt to fetch the next job" +
<                             " in queue was interrupted for server " +
<                             manager.getServerURL(), excp);
<                     continue;
<                 }
< 
<                 // Dispatch to the implementation based upon the job type. When
<                 // done indicate we are done.
<                 switch (job.jobType) {
<                     case SYNC:
<                         syncImpl();
<                         break;
<                     case DELETE:
<                         deleteImpl(job.avatar);
<                         break;
<                     case UPLOAD:
<                         uploadFilesImpl(job.avatar);
<                         break;
<                     case GETURL:
<                         job.url = getURLImpl(job.avatar);
<                         break;
<                 }
<                 job.setJobDone();
<             }
<         }
< 
<         /**
843c854
<                     LOGGER.log(Level.WARNING, "Unable to delete avatar from" +
---
>                     logger.log(Level.WARNING, "Unable to delete avatar from" +
853c864
<                     LOGGER.info("Deleting existing avatar directory locally" +
---
>                     logger.info("Deleting existing avatar directory locally" +
858c869
<                         LOGGER.log(Level.WARNING, "Unable to delete avatar" +
---
>                         logger.log(Level.WARNING, "Unable to delete avatar" +
863c874
<                     LOGGER.info("Did not find evolver avatar directory locally" +
---
>                     logger.info("Did not find evolver avatar directory locally" +
883c894
<                 LOGGER.severe("No record of avatar " + avatarName +
---
>                 logger.severe("No record of avatar " + avatarName +
892c903
<                 LOGGER.log(Level.WARNING, "Unable to fetch URL for server" +
---
>                 logger.log(Level.WARNING, "Unable to fetch URL for server" +
904c915
<             LOGGER.info("Beginning sychronization of server " +
---
>             logger.info("Beginning sychronization of server " +
922c933
<                         LOGGER.info("Found server avatar resource " +
---
>                         logger.info("Found server avatar resource " +
928c939
<                         LOGGER.info("Looking at server avatar named " +
---
>                         logger.info("Looking at server avatar named " +
936c947
<                             LOGGER.info("Found a previous version named " +
---
>                             logger.info("Found a previous version named " +
950c961
<                                 LOGGER.info("Previous version of avatar" +
---
>                                 logger.info("Previous version of avatar" +
974c985
<                     LOGGER.info("Taking a look at all of our local avatars");
---
>                     logger.info("Taking a look at all of our local avatars");
980c991
<                         LOGGER.info("Looking at local avatar named " +
---
>                         logger.info("Looking at local avatar named " +
989c1000
<                             LOGGER.info("Server version for avatar named " +
---
>                             logger.info("Server version for avatar named " +
997c1008
<                             LOGGER.info("Server version for avatar named " +
---
>                             logger.info("Server version for avatar named " +
1009c1020
<                             LOGGER.info("Server version for avatar named " +
---
>                             logger.info("Server version for avatar named " +
1027c1038
<                     LOGGER.info("Adding Server avatar to download list " +
---
>                     logger.info("Adding Server avatar to download list " +
1037c1048
<                 LOGGER.info("Doing upload of local avatars, number to upload " +
---
>                 logger.info("Doing upload of local avatars, number to upload " +
1041c1052
<                     LOGGER.info("Uploading Local avatar to server " +
---
>                     logger.info("Uploading Local avatar to server " +
1053c1064
<                 LOGGER.info("Doing download of local avatars to the server," +
---
>                 logger.info("Doing download of local avatars to the server," +
1057c1068
<                     LOGGER.info("Downloading server avatar named " +
---
>                     logger.info("Downloading server avatar named " +
1063c1074
<                         LOGGER.info("Error download files from server");
---
>                         logger.info("Error download files from server");
1076c1087
<                 LOGGER.info("Adding new local avatars to system, " +
---
>                 logger.info("Adding new local avatars to system, " +
1081c1092
<                         LOGGER.info("Adding new local avatar to system " +
---
>                         logger.info("Adding new local avatar to system " +
1090c1101
<                 LOGGER.log(Level.WARNING, "Error synchronizing with server " +
---
>                 logger.log(Level.WARNING, "Error synchronizing with server " +
1119c1130
<                 LOGGER.log(Level.WARNING, "Unable to upload xml config file " +
---
>                 logger.log(Level.WARNING, "Unable to upload xml config file " +
1127c1138
<                 LOGGER.info("Invalid file name for xml config file " +
---
>                 logger.info("Invalid file name for xml config file " +
1139c1150
<                     LOGGER.info("Unable to find local avatar directory " +
---
>                     logger.info("Unable to find local avatar directory " +
1144c1155
<                 LOGGER.log(Level.WARNING, "Unable to find local avatar " +
---
>                 logger.log(Level.WARNING, "Unable to find local avatar " +
1153c1164
<                 LOGGER.log(Level.WARNING, "Unable to transfer files from " +
---
>                 logger.log(Level.WARNING, "Unable to transfer files from " +
1184c1195
<                 LOGGER.info("Local avatar created in resource " +
---
>                 logger.info("Local avatar created in resource " +
1188c1199
<                 LOGGER.log(Level.WARNING, "Error downloading server " +
---
>                 logger.log(Level.WARNING, "Error downloading server " +
1196c1207
<                 LOGGER.warning("Invalid file name for xml config file " +
---
>                 logger.warning("Invalid file name for xml config file " +
1208c1219
<                     LOGGER.warning("Unable to find remote avatar directory " +
---
>                     logger.warning("Unable to find remote avatar directory " +
1213c1224
<                 LOGGER.log(Level.WARNING, "Unable to find remote avatar " +
---
>                 logger.log(Level.WARNING, "Unable to find remote avatar " +
1222c1233
<                 LOGGER.log(Level.WARNING, "Unable to transfer files from " +
---
>                 logger.log(Level.WARNING, "Unable to transfer files from " +
