mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-10 11:29:38 +00:00
catching heap memory errors
This commit is contained in:
parent
3bfa34f4c3
commit
18cc446063
@ -26,7 +26,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: AddMoteDialog.java,v 1.3 2007/01/10 14:59:07 fros4943 Exp $
|
* $Id: AddMoteDialog.java,v 1.4 2007/11/29 05:37:35 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.dialogs;
|
package se.sics.cooja.dialogs;
|
||||||
@ -44,7 +44,7 @@ import se.sics.cooja.interfaces.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A dialog for adding motes.
|
* A dialog for adding motes.
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
public class AddMoteDialog extends JDialog {
|
public class AddMoteDialog extends JDialog {
|
||||||
@ -69,11 +69,11 @@ public class AddMoteDialog extends JDialog {
|
|||||||
startZ, endZ;
|
startZ, endZ;
|
||||||
private JComboBox positionDistributionBox, ipDistributionBox;
|
private JComboBox positionDistributionBox, ipDistributionBox;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a dialog which enables a user to create and add motes of the given
|
* Shows a dialog which enables a user to create and add motes of the given
|
||||||
* type.
|
* type.
|
||||||
*
|
*
|
||||||
* @param parentFrame
|
* @param parentFrame
|
||||||
* Parent frame for dialog
|
* Parent frame for dialog
|
||||||
* @param simulation
|
* @param simulation
|
||||||
@ -99,7 +99,7 @@ public class AddMoteDialog extends JDialog {
|
|||||||
super(frame, "Add motes (" + moteType.getDescription() + ")", true);
|
super(frame, "Add motes (" + moteType.getDescription() + ")", true);
|
||||||
this.moteType = moteType;
|
this.moteType = moteType;
|
||||||
this.simulation = simulation;
|
this.simulation = simulation;
|
||||||
|
|
||||||
JLabel label;
|
JLabel label;
|
||||||
JPanel mainPane = new JPanel();
|
JPanel mainPane = new JPanel();
|
||||||
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
|
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
|
||||||
@ -143,6 +143,7 @@ public class AddMoteDialog extends JDialog {
|
|||||||
numberField = new JFormattedTextField(integerFormat);
|
numberField = new JFormattedTextField(integerFormat);
|
||||||
numberField.setValue(new Integer(1));
|
numberField.setValue(new Integer(1));
|
||||||
numberField.setColumns(10);
|
numberField.setColumns(10);
|
||||||
|
numberField.addFocusListener(myEventHandler);
|
||||||
numberField.addPropertyChangeListener("value", myEventHandler);
|
numberField.addPropertyChangeListener("value", myEventHandler);
|
||||||
numberOfMotesField = numberField;
|
numberOfMotesField = numberField;
|
||||||
|
|
||||||
@ -163,8 +164,9 @@ public class AddMoteDialog extends JDialog {
|
|||||||
Vector<Class<? extends IPDistributor>> ipDistributors = simulation.getGUI()
|
Vector<Class<? extends IPDistributor>> ipDistributors = simulation.getGUI()
|
||||||
.getRegisteredIPDistributors();
|
.getRegisteredIPDistributors();
|
||||||
String[] ipDistributions = new String[ipDistributors.size()];
|
String[] ipDistributions = new String[ipDistributors.size()];
|
||||||
for (int i = 0; i < ipDistributions.length; i++)
|
for (int i = 0; i < ipDistributions.length; i++) {
|
||||||
ipDistributions[i] = GUI.getDescriptionOf(ipDistributors.get(i));
|
ipDistributions[i] = GUI.getDescriptionOf(ipDistributors.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
comboBox = new JComboBox(ipDistributions);
|
comboBox = new JComboBox(ipDistributions);
|
||||||
|
|
||||||
@ -191,8 +193,9 @@ public class AddMoteDialog extends JDialog {
|
|||||||
Vector<Class<? extends Positioner>> positioners = simulation.getGUI()
|
Vector<Class<? extends Positioner>> positioners = simulation.getGUI()
|
||||||
.getRegisteredPositioners();
|
.getRegisteredPositioners();
|
||||||
String[] posDistributions = new String[positioners.size()];
|
String[] posDistributions = new String[positioners.size()];
|
||||||
for (int i = 0; i < posDistributions.length; i++)
|
for (int i = 0; i < posDistributions.length; i++) {
|
||||||
posDistributions[i] = GUI.getDescriptionOf(positioners.get(i));
|
posDistributions[i] = GUI.getDescriptionOf(positioners.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
comboBox = new JComboBox(posDistributions);
|
comboBox = new JComboBox(posDistributions);
|
||||||
|
|
||||||
@ -226,6 +229,7 @@ public class AddMoteDialog extends JDialog {
|
|||||||
numberField = new JFormattedTextField(doubleFormat);
|
numberField = new JFormattedTextField(doubleFormat);
|
||||||
numberField.setValue(new Double(0.0));
|
numberField.setValue(new Double(0.0));
|
||||||
numberField.setColumns(4);
|
numberField.setColumns(4);
|
||||||
|
numberField.addFocusListener(myEventHandler);
|
||||||
numberField.addPropertyChangeListener("value", myEventHandler);
|
numberField.addPropertyChangeListener("value", myEventHandler);
|
||||||
startX = numberField;
|
startX = numberField;
|
||||||
smallPane.add(numberField);
|
smallPane.add(numberField);
|
||||||
@ -238,6 +242,7 @@ public class AddMoteDialog extends JDialog {
|
|||||||
numberField = new JFormattedTextField(doubleFormat);
|
numberField = new JFormattedTextField(doubleFormat);
|
||||||
numberField.setValue(new Double(100.0));
|
numberField.setValue(new Double(100.0));
|
||||||
numberField.setColumns(4);
|
numberField.setColumns(4);
|
||||||
|
numberField.addFocusListener(myEventHandler);
|
||||||
numberField.addPropertyChangeListener("value", myEventHandler);
|
numberField.addPropertyChangeListener("value", myEventHandler);
|
||||||
endX = numberField;
|
endX = numberField;
|
||||||
smallPane.add(numberField);
|
smallPane.add(numberField);
|
||||||
@ -263,6 +268,7 @@ public class AddMoteDialog extends JDialog {
|
|||||||
numberField = new JFormattedTextField(doubleFormat);
|
numberField = new JFormattedTextField(doubleFormat);
|
||||||
numberField.setValue(new Double(0.0));
|
numberField.setValue(new Double(0.0));
|
||||||
numberField.setColumns(4);
|
numberField.setColumns(4);
|
||||||
|
numberField.addFocusListener(myEventHandler);
|
||||||
numberField.addPropertyChangeListener("value", myEventHandler);
|
numberField.addPropertyChangeListener("value", myEventHandler);
|
||||||
startY = numberField;
|
startY = numberField;
|
||||||
smallPane.add(numberField);
|
smallPane.add(numberField);
|
||||||
@ -275,6 +281,7 @@ public class AddMoteDialog extends JDialog {
|
|||||||
numberField = new JFormattedTextField(doubleFormat);
|
numberField = new JFormattedTextField(doubleFormat);
|
||||||
numberField.setValue(new Double(100.0));
|
numberField.setValue(new Double(100.0));
|
||||||
numberField.setColumns(4);
|
numberField.setColumns(4);
|
||||||
|
numberField.addFocusListener(myEventHandler);
|
||||||
numberField.addPropertyChangeListener("value", myEventHandler);
|
numberField.addPropertyChangeListener("value", myEventHandler);
|
||||||
endY = numberField;
|
endY = numberField;
|
||||||
smallPane.add(numberField);
|
smallPane.add(numberField);
|
||||||
@ -300,6 +307,7 @@ public class AddMoteDialog extends JDialog {
|
|||||||
numberField = new JFormattedTextField(doubleFormat);
|
numberField = new JFormattedTextField(doubleFormat);
|
||||||
numberField.setValue(new Double(0.0));
|
numberField.setValue(new Double(0.0));
|
||||||
numberField.setColumns(4);
|
numberField.setColumns(4);
|
||||||
|
numberField.addFocusListener(myEventHandler);
|
||||||
numberField.addPropertyChangeListener("value", myEventHandler);
|
numberField.addPropertyChangeListener("value", myEventHandler);
|
||||||
startZ = numberField;
|
startZ = numberField;
|
||||||
smallPane.add(numberField);
|
smallPane.add(numberField);
|
||||||
@ -312,6 +320,7 @@ public class AddMoteDialog extends JDialog {
|
|||||||
numberField = new JFormattedTextField(doubleFormat);
|
numberField = new JFormattedTextField(doubleFormat);
|
||||||
numberField.setValue(new Double(0.0));
|
numberField.setValue(new Double(0.0));
|
||||||
numberField.setColumns(4);
|
numberField.setColumns(4);
|
||||||
|
numberField.addFocusListener(myEventHandler);
|
||||||
numberField.addPropertyChangeListener("value", myEventHandler);
|
numberField.addPropertyChangeListener("value", myEventHandler);
|
||||||
endZ = numberField;
|
endZ = numberField;
|
||||||
smallPane.add(numberField);
|
smallPane.add(numberField);
|
||||||
@ -399,8 +408,14 @@ public class AddMoteDialog extends JDialog {
|
|||||||
public void propertyChange(PropertyChangeEvent e) {
|
public void propertyChange(PropertyChangeEvent e) {
|
||||||
checkSettings();
|
checkSettings();
|
||||||
}
|
}
|
||||||
public void focusGained(FocusEvent e) {
|
public void focusGained(final FocusEvent e) {
|
||||||
// NOP
|
if (e.getSource() instanceof JFormattedTextField) {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
((JFormattedTextField) e.getSource()).selectAll();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void focusLost(FocusEvent e) {
|
public void focusLost(FocusEvent e) {
|
||||||
checkSettings();
|
checkSettings();
|
||||||
@ -410,97 +425,112 @@ public class AddMoteDialog extends JDialog {
|
|||||||
newMotes = null;
|
newMotes = null;
|
||||||
dispose();
|
dispose();
|
||||||
} else if (e.getActionCommand().equals("add")) {
|
} else if (e.getActionCommand().equals("add")) {
|
||||||
newMotes = new Vector<Mote>();
|
try {
|
||||||
|
newMotes = new Vector<Mote>();
|
||||||
|
|
||||||
// Create new motes
|
// Create new motes
|
||||||
int motesToAdd = ((Number) numberOfMotesField.getValue()).intValue();
|
int motesToAdd = ((Number) numberOfMotesField.getValue()).intValue();
|
||||||
while (newMotes.size() < motesToAdd) {
|
while (newMotes.size() < motesToAdd) {
|
||||||
Mote newMote = moteType.generateMote(simulation);
|
Mote newMote = moteType.generateMote(simulation);
|
||||||
newMotes.add(newMote);
|
newMotes.add(newMote);
|
||||||
}
|
|
||||||
|
|
||||||
// Position new motes
|
|
||||||
Class<? extends Positioner> positionerClass = null;
|
|
||||||
for (Class<? extends Positioner> positioner : simulation.getGUI()
|
|
||||||
.getRegisteredPositioners()) {
|
|
||||||
if (GUI.getDescriptionOf(positioner).equals(
|
|
||||||
(String) positionDistributionBox.getSelectedItem()))
|
|
||||||
positionerClass = positioner;
|
|
||||||
}
|
|
||||||
|
|
||||||
Positioner positioner = Positioner.generateInterface(positionerClass,
|
|
||||||
((Number) numberOfMotesField.getValue()).intValue(),
|
|
||||||
((Number) startX.getValue()).doubleValue(), ((Number) endX
|
|
||||||
.getValue()).doubleValue(), ((Number) startY.getValue())
|
|
||||||
.doubleValue(), ((Number) endY.getValue()).doubleValue(),
|
|
||||||
((Number) startZ.getValue()).doubleValue(), ((Number) endZ
|
|
||||||
.getValue()).doubleValue());
|
|
||||||
|
|
||||||
if (positioner == null) {
|
|
||||||
logger.fatal("Could not create positioner");
|
|
||||||
dispose();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < newMotes.size(); i++) {
|
|
||||||
Position newPosition = newMotes.get(i).getInterfaces().getPosition();
|
|
||||||
if (newPosition != null) {
|
|
||||||
double[] newPositionArray = positioner.getNextPosition();
|
|
||||||
if (newPositionArray.length >= 3)
|
|
||||||
newPosition.setCoordinates(newPositionArray[0],
|
|
||||||
newPositionArray[1], newPositionArray[2]);
|
|
||||||
else if (newPositionArray.length >= 2)
|
|
||||||
newPosition.setCoordinates(newPositionArray[0],
|
|
||||||
newPositionArray[1], 0);
|
|
||||||
else if (newPositionArray.length >= 1)
|
|
||||||
newPosition.setCoordinates(newPositionArray[0], 0, 0);
|
|
||||||
else
|
|
||||||
newPosition.setCoordinates(0, 0, 0);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Set unique mote id's for all new motes
|
// Position new motes
|
||||||
int nextMoteID = 1;
|
Class<? extends Positioner> positionerClass = null;
|
||||||
for (int i = 0; i < simulation.getMotesCount(); i++) {
|
for (Class<? extends Positioner> positioner : simulation.getGUI()
|
||||||
MoteID moteID = simulation.getMote(i).getInterfaces()
|
.getRegisteredPositioners()) {
|
||||||
.getMoteID();
|
if (GUI.getDescriptionOf(positioner).equals(
|
||||||
if (moteID != null && moteID.getMoteID() >= nextMoteID)
|
positionDistributionBox.getSelectedItem())) {
|
||||||
nextMoteID = moteID.getMoteID() + 1;
|
positionerClass = positioner;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < newMotes.size(); i++) {
|
|
||||||
MoteID moteID = newMotes.get(i).getInterfaces().getMoteID();
|
|
||||||
if (moteID != null) {
|
|
||||||
moteID.setMoteID(nextMoteID++);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// IP address new motes
|
Positioner positioner = Positioner.generateInterface(positionerClass,
|
||||||
Class<? extends IPDistributor> ipDistClass = null;
|
((Number) numberOfMotesField.getValue()).intValue(),
|
||||||
for (Class<? extends IPDistributor> ipDistributor : simulation.getGUI()
|
((Number) startX.getValue()).doubleValue(), ((Number) endX
|
||||||
.getRegisteredIPDistributors()) {
|
.getValue()).doubleValue(), ((Number) startY.getValue())
|
||||||
if (GUI.getDescriptionOf(ipDistributor).equals(
|
.doubleValue(), ((Number) endY.getValue()).doubleValue(),
|
||||||
(String) ipDistributionBox.getSelectedItem()))
|
((Number) startZ.getValue()).doubleValue(), ((Number) endZ
|
||||||
ipDistClass = ipDistributor;
|
.getValue()).doubleValue());
|
||||||
}
|
|
||||||
|
|
||||||
IPDistributor ipDistributor = IPDistributor.generateIPDistributor(
|
if (positioner == null) {
|
||||||
ipDistClass, newMotes);
|
logger.fatal("Could not create positioner");
|
||||||
|
dispose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < newMotes.size(); i++) {
|
||||||
|
Position newPosition = newMotes.get(i).getInterfaces().getPosition();
|
||||||
|
if (newPosition != null) {
|
||||||
|
double[] newPositionArray = positioner.getNextPosition();
|
||||||
|
if (newPositionArray.length >= 3) {
|
||||||
|
newPosition.setCoordinates(newPositionArray[0],
|
||||||
|
newPositionArray[1], newPositionArray[2]);
|
||||||
|
} else if (newPositionArray.length >= 2) {
|
||||||
|
newPosition.setCoordinates(newPositionArray[0],
|
||||||
|
newPositionArray[1], 0);
|
||||||
|
} else if (newPositionArray.length >= 1) {
|
||||||
|
newPosition.setCoordinates(newPositionArray[0], 0, 0);
|
||||||
|
} else {
|
||||||
|
newPosition.setCoordinates(0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set unique mote id's for all new motes
|
||||||
|
int nextMoteID = 1;
|
||||||
|
for (int i = 0; i < simulation.getMotesCount(); i++) {
|
||||||
|
MoteID moteID = simulation.getMote(i).getInterfaces()
|
||||||
|
.getMoteID();
|
||||||
|
if (moteID != null && moteID.getMoteID() >= nextMoteID) {
|
||||||
|
nextMoteID = moteID.getMoteID() + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < newMotes.size(); i++) {
|
||||||
|
MoteID moteID = newMotes.get(i).getInterfaces().getMoteID();
|
||||||
|
if (moteID != null) {
|
||||||
|
moteID.setMoteID(nextMoteID++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IP address new motes
|
||||||
|
Class<? extends IPDistributor> ipDistClass = null;
|
||||||
|
for (Class<? extends IPDistributor> ipDistributor : simulation.getGUI()
|
||||||
|
.getRegisteredIPDistributors()) {
|
||||||
|
if (GUI.getDescriptionOf(ipDistributor).equals(
|
||||||
|
ipDistributionBox.getSelectedItem())) {
|
||||||
|
ipDistClass = ipDistributor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IPDistributor ipDistributor = IPDistributor.generateIPDistributor(
|
||||||
|
ipDistClass, newMotes);
|
||||||
|
|
||||||
|
if (ipDistributor == null) {
|
||||||
|
logger.fatal("Could not create IP distributor");
|
||||||
|
dispose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < newMotes.size(); i++) {
|
||||||
|
String newIPString = ipDistributor.getNextIPAddress();
|
||||||
|
if (newMotes.get(i).getInterfaces().getIPAddress() != null) {
|
||||||
|
newMotes.get(i).getInterfaces().getIPAddress().setIPString(
|
||||||
|
newIPString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ipDistributor == null) {
|
|
||||||
logger.fatal("Could not create IP distributor");
|
|
||||||
dispose();
|
dispose();
|
||||||
return;
|
} catch (OutOfMemoryError e2) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
AddMoteDialog.this,
|
||||||
|
"Out of memory!\nException message: \"" + e2.getMessage() + "\"\n\n" +
|
||||||
|
"Reduce number of nodes or start COOJA with more memory (\">ant run_bigmem\").",
|
||||||
|
"Not enough heap memory!", JOptionPane.ERROR_MESSAGE
|
||||||
|
);
|
||||||
|
newMotes = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < newMotes.size(); i++) {
|
|
||||||
String newIPString = ipDistributor.getNextIPAddress();
|
|
||||||
if (newMotes.get(i).getInterfaces().getIPAddress() != null)
|
|
||||||
newMotes.get(i).getInterfaces().getIPAddress().setIPString(
|
|
||||||
newIPString);
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user