Skip to content

Commit

Permalink
Merge pull request #42 from slipegg/feature/refactor_code
Browse files Browse the repository at this point in the history
Refactor some log related codes
  • Loading branch information
slipegg authored Oct 13, 2024
2 parents 459241b + a61f88b commit 09e50ef
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/lgdcloudsim/core/CloudSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class CloudSim implements Simulation {
* The simulation time.
*/
double clock;

/**
* The simulation time in string format.
*/
String clockStr;
/**
* A flag to indicate if the simulation is running or not.
*/
Expand Down Expand Up @@ -116,7 +121,7 @@ public class CloudSim implements Simulation {
* Creates a new CloudSim instance.
*/
public CloudSim() {
clock = 0;
setClock(0);
this.entityList = new ArrayList<>();
this.future = new FutureQueue();
this.deferred = new DeferredQueue();
Expand All @@ -132,12 +137,13 @@ public double clock() {

@Override
public String clockStr() {
return "%.2f ms".formatted(clock);
return clockStr;
}

@Override
public Simulation setClock(double time) {
this.clock = time;
this.clockStr = "%.2f ms".formatted(clock);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void datacenterAddCollaborationId(Datacenter datacenter, int collaborati
if (datacenter == null) return;
Set<Integer> collaborationIds = datacenter.getCollaborationIds();
if (collaborationIds.contains(collaborationId)) {
LOGGER.warn("the datacenter(" + datacenter + ") already belongs to the collaboration " + collaborationId);
LOGGER.warn("the datacenter({}) already belongs to the collaboration {}", datacenter, collaborationId);
} else {
collaborationIds.add(collaborationId);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ private void datacenterRemoveCollaborationId(Datacenter datacenter, int collabor
if (datacenter == null) return;
Set<Integer> collaborationIds = datacenter.getCollaborationIds();
if (!collaborationIds.contains(collaborationId)) {
LOGGER.warn("the datacenter(" + datacenter + ") does not belong to the collaboration " + collaborationId + " to be removed");
LOGGER.warn("the datacenter({})'s collaborationIds: {}", datacenter, collaborationIds);
} else {
collaborationIds.remove(collaborationId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public SqlRecordDetailScheduleTime(String dbDir, String dbName, String userReque
try {
conn = DriverManager.getConnection("jdbc:sqlite:" + this.dbPath);
conn.setAutoCommit(false);
LOGGER.info("Opened " + this.dbPath + " successfully");
LOGGER.info("Opened {} successfully", this.dbPath);
stmt = conn.createStatement();

createUserRequestTable();
Expand Down Expand Up @@ -371,7 +371,7 @@ public void recordInstanceGroupAllInfo(InstanceGroup instanceGroup) {
stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
LOGGER.error("The instance group " + instanceGroup.getId() + " recorded error {}", e.getMessage());
LOGGER.error("The instance group {} recorded error {}", instanceGroup.getId(), e.getMessage());
try {
sql = "SELECT * FROM " + this.instanceGroupTableName + " WHERE id = " + instanceGroup.getId() + ";";
ResultSet rs = stmt.executeQuery(sql);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/lgdcloudsim/record/SqlRecordSimple.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public SqlRecordSimple(String dbDir, String dbName, String userRequestTableName,
try {
conn = DriverManager.getConnection("jdbc:sqlite:" + this.dbPath);
conn.setAutoCommit(false);
LOGGER.info("Opened " + this.dbPath + " successfully");
LOGGER.info("Opened {} successfully", this.dbPath);
stmt = conn.createStatement();

createUserRequestTable();
Expand Down

0 comments on commit 09e50ef

Please sign in to comment.