annotate java/src/uk/ac/qmul/eecs/ccmi/network/LockMessage.java @ 1:e3935c01cde2 tip

moved license of PdPersistenceManager to the beginning of the file
author Fiore Martin <f.martin@qmul.ac.uk>
date Tue, 08 Jul 2014 19:52:03 +0100
parents 78b7fc5391a2
children
rev   line source
f@0 1 /*
f@0 2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
f@0 3
f@0 4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
f@0 5
f@0 6 This program is free software: you can redistribute it and/or modify
f@0 7 it under the terms of the GNU General Public License as published by
f@0 8 the Free Software Foundation, either version 3 of the License, or
f@0 9 (at your option) any later version.
f@0 10
f@0 11 This program is distributed in the hope that it will be useful,
f@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
f@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f@0 14 GNU General Public License for more details.
f@0 15
f@0 16 You should have received a copy of the GNU General Public License
f@0 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
f@0 18 */
f@0 19
f@0 20 package uk.ac.qmul.eecs.ccmi.network;
f@0 21
f@0 22 /**
f@0 23 * This class represents a lock message,through which the clients get exclusivity on
f@0 24 * editing the elements of the diagram. The class is used by both the client,
f@0 25 * to request a lock, and the server, to acknowledge the success/failure of the request.
f@0 26 *
f@0 27 * The argument of the message can be either the path to a three node or the id of a diagram element.
f@0 28 * The former is used for lock for notes editing which can concern every tree node in the tree,
f@0 29 * the latter for all the other types of lock as they only concern diagram elements.
f@0 30 * The path to a tree node is a sequence of integers representing the index of the children
f@0 31 * from the root to the affected node. So for instance 4,2,3 would be the third son of the
f@0 32 * second son of the fourth son of the root node.
f@0 33 */
f@0 34 public class LockMessage extends Message {
f@0 35
f@0 36 /**
f@0 37 * Creates a lock message for the given diagram and with the given timestamp.
f@0 38 *
f@0 39 * @param name the message name
f@0 40 * @param timestamp the time when the message was issued
f@0 41 * @param diagram the name of the diagram this message refers to
f@0 42 * @param args arguments of the message
f@0 43 * @param source the source that generated this message see {@link DiagramEventActionSource}
f@0 44 */
f@0 45 public LockMessage(Name name, long timestamp, String diagram, Object[] args, Object source) {
f@0 46 super(timestamp, diagram,source);
f@0 47 this.args = args;
f@0 48 this.name = name;
f@0 49 }
f@0 50
f@0 51 /**
f@0 52 * Creates a lock message for the given diagram and timestamp of the moment
f@0 53 * the message is created.
f@0 54 *
f@0 55 * @param name the message name
f@0 56 * @param diagram the name of the diagram this message refers to
f@0 57 * @param args arguments of the message
f@0 58 * @param source the source that generated this message see {@link DiagramEventActionSource}
f@0 59 */
f@0 60 public LockMessage(Name name, String diagram, Object[] args, DiagramEventActionSource source) {
f@0 61 super(diagram,source);
f@0 62 this.args = args;
f@0 63 this.name = name;
f@0 64 }
f@0 65
f@0 66 public LockMessage(Name name, long timestamp, String diagram, long id, DiagramEventActionSource source) {
f@0 67 this(name,timestamp,diagram,new Object[]{id},source);
f@0 68 }
f@0 69
f@0 70 public LockMessage(Name name, String diagram, long id, DiagramEventActionSource source){
f@0 71 this(name,diagram,new Object[]{id},source);
f@0 72 }
f@0 73
f@0 74 @Override
f@0 75 public Name getName() {
f@0 76 return name;
f@0 77 }
f@0 78
f@0 79 public Object getArgAt(int index) {
f@0 80 return args[index];
f@0 81 }
f@0 82
f@0 83 public Object[] getArgs(){
f@0 84 return args;
f@0 85 }
f@0 86
f@0 87 public int getArgNum(){
f@0 88 return args.length;
f@0 89 }
f@0 90
f@0 91 @Override
f@0 92 public DiagramEventActionSource getSource(){
f@0 93 return (DiagramEventActionSource)super.getSource();
f@0 94 }
f@0 95
f@0 96 public static LockMessage.Name valueOf(String n){
f@0 97 Name name = Name.NONE_L;
f@0 98 try {
f@0 99 name = Name.valueOf(n);
f@0 100 }catch(IllegalArgumentException iae){
f@0 101 iae.printStackTrace();
f@0 102 return Name.NONE_L;
f@0 103 }
f@0 104 return name;
f@0 105 }
f@0 106
f@0 107 /** used to distinguish between different kinds of messages. */
f@0 108 public static final String NAME_POSTFIX = "_L";
f@0 109 public static final String GET_LOCK_PREFIX = "GET_";
f@0 110 public static final String YIELD_LOCK_PREFIX = "YIELD_";
f@0 111 private Name name;
f@0 112 private Object[] args;
f@0 113
f@0 114 /**
f@0 115 * enum containing all the possible lock messages that can be exchanged
f@0 116 * between server and client in either direction.
f@0 117 */
f@0 118 public static enum Name implements Message.MessageName {
f@0 119 GET_DELETE_L,
f@0 120 GET_NAME_L,
f@0 121 GET_PROPERTIES_L,
f@0 122 GET_EDGE_END_L,
f@0 123 GET_MOVE_L,
f@0 124 GET_NOTES_L,
f@0 125 GET_BOOKMARK_L,
f@0 126 GET_MUST_EXIST_L,
f@0 127
f@0 128 YIELD_DELETE_L,
f@0 129 YIELD_NAME_L,
f@0 130 YIELD_PROPERTIES_L,
f@0 131 YIELD_EDGE_END_L,
f@0 132 YIELD_MOVE_L,
f@0 133 YIELD_NOTES_L,
f@0 134 YIELD_BOOKMARK_L,
f@0 135 YIELD_MUST_EXISTS_L,
f@0 136
f@0 137 YES_L,
f@0 138 NO_L,
f@0 139 NONE_L;
f@0 140 }
f@0 141 }