public BStream(BType type, String name) { if (((BStreamType) type).getConstrainedType() == null) { throw new BallerinaException("a stream cannot be declared without a constraint"); } try { this.brokerInstance = BallerinaBroker.getBrokerInstance(); } catch (Exception e) { throw new BallerinaException("Error starting up internal broker for streams"); } this.constraintType = ((BStreamType) type).getConstrainedType(); this.type = new BStreamType(constraintType); if (constraintType instanceof BIndexedType) { this.topicName = TOPIC_NAME_PREFIX + ((BIndexedType) constraintType).getElementType() + "_" + name; } else if (constraintType != null) { this.topicName = TOPIC_NAME_PREFIX + constraintType + "_" + name; } else { this.topicName = TOPIC_NAME_PREFIX + name; //TODO: check for improvement } topicName = topicName.concat("_").concat(UUID.randomUUID().toString()); this.streamId = name; }
@Override public BType getConstrainedType(char typeChar, BType constraint) { switch (typeChar) { case 'J': if (constraint == null) { return BTypes.typeJSON; } return new BJSONType(constraint); case 'D': if (constraint == null) { return BTypes.typeTable; } return new BTableType(constraint); case 'M': if (constraint == null || constraint == BTypes.typeAny) { return BTypes.typeMap; } return new BMapType(constraint); case 'H': return new BStreamType(constraint); case 'G': case 'T': case 'X': case 'Q': default: return constraint; } }
return isAssignable(((BStreamType) rhsType).getConstrainedType(), ((BStreamType) lhsType).getConstrainedType(), unresolvedTypes);