Skip to content

Machine entity#7

Open
tabgok wants to merge 3 commits intomasterfrom
MachineEntity
Open

Machine entity#7
tabgok wants to merge 3 commits intomasterfrom
MachineEntity

Conversation

@tabgok
Copy link
Owner

@tabgok tabgok commented Mar 30, 2017

Continuuing with adding classes - This is the first commit from the "Entity" portion of the project, or the in-memory model of the Machine.

import com.tabgok.harvester.commands.CommandResult;


public abstract class Entity {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this an interface. abstract classes are rarely what you want.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


private Machine(){}

public static Machine getMachine(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"getMachine()" sounds to me like there's just one. simply ".create()" is pretty conventional for something like this.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

* everything within a machine from Hardware to Filesystems to applications.
*/
public class Machine extends Entity {
private StringData MachineID;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a mutable ID on an object "smells" like we should rethink the object model here. it can force us to worry about all sorts of shit later on that we won't want to.

do you have a reason for having it be mutable?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not picking and choosing fields for what is immutable and what isn't, maybe I should. For instance, if a disk gets moved in/out of a machine, I'd expect the values to update accordingly -> but then again, I'd want a new disk and not the old one.

The machine is difficult though, because the ID is read from disk (there's a linux file for ID) so I can't set it in the constructor easily, at the moment.

* everything within a machine from Hardware to Filesystems to applications.
*/
public class Machine extends Entity {
private StringData MachineID;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what StringData is, but if your ID isn't a String, it should probably be some interface MachineId which hides all the details.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringData{
final string value;
final string variable;
final timestamp data;
}

* everything within a machine from Hardware to Filesystems to applications.
*/
public class Machine extends Entity {
private StringData MachineID;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/MachineID/machineId/ (read, or at least skim, oracle's java style guide)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oracle's style guide has a large warning saying "hasn't been updated since 1999" (http://www.oracle.com/technetwork/java/codeconvtoc-136057.html). Should I look there or here: https://google.github.io/styleguide/javaguide.html or somewhere else?

*
* @return Return the active mounted partition points on the machine
*/
public String[] getmountedFilesystemIDs(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are really good arguments for always passing around immutable data structures, and very few good arguments for passing around mutable ones. This is a good example of why mutable data structures are problematic -- you have to make a copy of it to return it from a method, and (something you missed here) you have to worry about concurrency issues.

at google, for example, this would return an ImmutableSet, and mountedFilesystems would be an ImmutableSet, so we could just return it.

Two options I can think of here:

  • Find a library with immutable data structures that you like and use that (the one we use is known publicly as guava)
  • just return a Set<String> that is a copy of the member variable; nobody wants an array.

* @param IDs Update this machine's mounted partitions
*/
public void updateMountedFilesystemIDs(Set<String> IDs){
mountedFilesystems.addAll(IDs);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are probably better off just making mountedFilesystems non-final, and saying mountedFilesystems = copySet(IDs);

or, continuing with the immutability conversation, if possible, don't let mountedFilesystems be changed for the life of the object.

*
* @param IDs Update this machine's mounted partitions
*/
public void updateMountedFilesystemIDs(Set<String> IDs){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/IDs/ids/

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

*
* @param ID Set this machine's ID
*/
public void setID(StringData ID){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ID/id/

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


import com.tabgok.harvester.commands.CommandResult;


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the package name and the class name are really vague, which might be OK but I can't tell without javadoc here explaining what this is :P

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I am implementing something similar to futures...but I don't have enough experience with those to know. A "command" is a generic "executed something" and a CommandResult is a "executed something's return value"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and "entity' is... ?

modify more after reading up on immutability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants