Skip to content
Snippets Groups Projects
Commit ff5517bc authored by Andreas Wundsam's avatar Andreas Wundsam
Browse files

openflowj/BasicFactory: inject factories to all newly created objects

parent 2e7883ee
No related branches found
No related tags found
No related merge requests found
...@@ -44,9 +44,20 @@ import org.openflow.protocol.vendor.OFVendorId; ...@@ -44,9 +44,20 @@ import org.openflow.protocol.vendor.OFVendorId;
*/ */
public class BasicFactory implements OFMessageFactory, OFActionFactory, public class BasicFactory implements OFMessageFactory, OFActionFactory,
OFStatisticsFactory, OFVendorDataFactory { OFStatisticsFactory, OFVendorDataFactory {
/**
* create and return a new instance of a message for OFType t. Also injects
* factories for those message types that implement the *FactoryAware
* interfaces.
*
* @return a newly created instance that may be modified / used freely by
* the caller
*/
@Override @Override
public OFMessage getMessage(OFType t) { public OFMessage getMessage(OFType t) {
return t.newInstance(); OFMessage message = t.newInstance();
injectFactories(message);
return message;
} }
@Override @Override
...@@ -92,18 +103,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory, ...@@ -92,18 +103,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
if (ofm == null) if (ofm == null)
return null; return null;
if (ofm instanceof OFActionFactoryAware) { injectFactories(ofm);
((OFActionFactoryAware)ofm).setActionFactory(this);
}
if (ofm instanceof OFMessageFactoryAware) {
((OFMessageFactoryAware)ofm).setMessageFactory(this);
}
if (ofm instanceof OFStatisticsFactoryAware) {
((OFStatisticsFactoryAware)ofm).setStatisticsFactory(this);
}
if (ofm instanceof OFVendorDataFactoryAware) {
((OFVendorDataFactoryAware)ofm).setVendorDataFactory(this);
}
ofm.readFrom(data); ofm.readFrom(data);
if (OFMessage.class.equals(ofm.getClass())) { if (OFMessage.class.equals(ofm.getClass())) {
// advance the position for un-implemented messages // advance the position for un-implemented messages
...@@ -124,6 +124,21 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory, ...@@ -124,6 +124,21 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
} }
} }
private void injectFactories(OFMessage ofm) {
if (ofm instanceof OFActionFactoryAware) {
((OFActionFactoryAware)ofm).setActionFactory(this);
}
if (ofm instanceof OFMessageFactoryAware) {
((OFMessageFactoryAware)ofm).setMessageFactory(this);
}
if (ofm instanceof OFStatisticsFactoryAware) {
((OFStatisticsFactoryAware)ofm).setStatisticsFactory(this);
}
if (ofm instanceof OFVendorDataFactoryAware) {
((OFVendorDataFactoryAware)ofm).setVendorDataFactory(this);
}
}
@Override @Override
public OFAction getAction(OFActionType t) { public OFAction getAction(OFActionType t) {
return t.newInstance(); return t.newInstance();
...@@ -194,7 +209,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory, ...@@ -194,7 +209,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
* length of statistics * length of statistics
* @param limit * @param limit
* number of statistics to grab; 0 == all * number of statistics to grab; 0 == all
* *
* @return list of statistics * @return list of statistics
*/ */
...@@ -230,7 +245,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory, ...@@ -230,7 +245,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
* though we have a full message. Found when NOX sent * though we have a full message. Found when NOX sent
* agg_stats request with wrong agg statistics length (52 * agg_stats request with wrong agg statistics length (52
* instead of 56) * instead of 56)
* *
* just throw the rest away, or we will break framing * just throw the rest away, or we will break framing
*/ */
data.readerIndex(start + length); data.readerIndex(start + length);
...@@ -247,7 +262,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory, ...@@ -247,7 +262,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
OFVendorDataType vendorDataType) { OFVendorDataType vendorDataType) {
if (vendorDataType == null) if (vendorDataType == null)
return null; return null;
return vendorDataType.newInstance(); return vendorDataType.newInstance();
} }
...@@ -259,6 +274,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory, ...@@ -259,6 +274,7 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
* @param length the length to the end of the enclosing message. * @param length the length to the end of the enclosing message.
* @return an OFVendorData instance * @return an OFVendorData instance
*/ */
@Override
public OFVendorData parseVendorData(int vendor, ChannelBuffer data, public OFVendorData parseVendorData(int vendor, ChannelBuffer data,
int length) { int length) {
OFVendorDataType vendorDataType = null; OFVendorDataType vendorDataType = null;
...@@ -268,13 +284,13 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory, ...@@ -268,13 +284,13 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
vendorDataType = vendorId.parseVendorDataType(data, length); vendorDataType = vendorId.parseVendorDataType(data, length);
data.resetReaderIndex(); data.resetReaderIndex();
} }
OFVendorData vendorData = getVendorData(vendorId, vendorDataType); OFVendorData vendorData = getVendorData(vendorId, vendorDataType);
if (vendorData == null) if (vendorData == null)
vendorData = new OFByteArrayVendorData(); vendorData = new OFByteArrayVendorData();
vendorData.readFrom(data, length); vendorData.readFrom(data, length);
return vendorData; return vendorData;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment